创建仓库

This commit is contained in:
lihongwei 2025-01-02 14:23:37 +08:00
commit 51e835a92e
79 changed files with 15259 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
*.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

1
app/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

64
app/build.gradle.kts Normal file
View File

@ -0,0 +1,64 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("kotlin-kapt")
}
android {
namespace = "com.wallpaper.wallpaperdream"
compileSdk = 34
defaultConfig {
applicationId = "com.wallpaper.wallpaperdream"
minSdk = 23
targetSdk = 34
versionCode = 1
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
viewBinding = true
}
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation("com.github.bumptech.glide:glide:4.16.0")
kapt("com.github.bumptech.glide:compiler:4.15.1")
implementation("androidx.room:room-runtime:2.6.1")
kapt("androidx.room:room-compiler:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
implementation ("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7")
}

21
app/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,24 @@
package com.wallpaper.wallpaperdream
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.wallpaper.wallpaperdream", appContext.packageName)
}
}

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WallpaperDream"
tools:targetApi="31">
<activity
android:name=".ui.activity.CategoryActivity"
android:exported="false" />
<activity
android:name=".ui.activity.ImageActivity"
android:exported="false" />
<activity
android:name=".ui.activity.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,49 @@
package com.wallpaper.wallpaperdream
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.util.Log
import com.wallpaper.wallpaperdream.data.repository.WallpaperRepository
import com.wallpaper.wallpaperdream.utils.JsonUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class MyApplication : Application() {
companion object {
private lateinit var instance: MyApplication
const val DB_VERSION = 1
const val DB_NAME = "wallpaper_database"
private const val PREF_NAME = "wallpaper_preferences"
private const val KEY_INITIALIZED = "isInitDatabase"
@JvmStatic
fun getContext(): Context {
return instance.applicationContext
}
}
override fun onCreate() {
super.onCreate()
instance = this
val preferences: SharedPreferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE)
val isDatabaseInit = preferences.getBoolean(KEY_INITIALIZED, false)
if (!isDatabaseInit) {
initDatabase()
preferences.edit().putBoolean(KEY_INITIALIZED, true).apply()
}
}
private fun initDatabase() {
CoroutineScope(Dispatchers.IO).launch {
val wallpaperRepository = WallpaperRepository(getContext())
val wallpaperDataList = JsonUtils.parseJson("wallpaper.json")
wallpaperRepository.insertAll(wallpaperDataList)
Log.d("MyApplication", "Database initialized: ${wallpaperDataList.size}");
}
}
}

View File

@ -0,0 +1,32 @@
package com.wallpaper.wallpaperdream.data.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.wallpaper.wallpaperdream.MyApplication
import com.wallpaper.wallpaperdream.data.database.dao.WallpaperDataDao
import com.wallpaper.wallpaperdream.data.database.entity.WallpaperData
@Database(entities = [WallpaperData::class], version = MyApplication.DB_VERSION)
abstract class AppDatabase : RoomDatabase() {
abstract fun wallpaperDataDao(): WallpaperDataDao
companion object {
@Volatile
private var INSTANCE: AppDatabase? = null
fun getInstance(context: Context): AppDatabase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
MyApplication.DB_NAME
).build()
INSTANCE = instance
instance
}
}
}
}

View File

@ -0,0 +1,37 @@
package com.wallpaper.wallpaperdream.data.database.dao
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.wallpaper.wallpaperdream.data.database.entity.WallpaperData
@Dao
interface WallpaperDataDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(wallpaperList: List<WallpaperData>)
@Update
suspend fun update(wallpaper: WallpaperData)
@Query("SELECT * FROM wallpapers LIMIT :limit OFFSET :offset")
fun getWallpapers(limit: Int, offset: Int): LiveData<List<WallpaperData>>
@Query("SELECT * FROM wallpapers WHERE id IN (SELECT MIN(id) FROM wallpapers GROUP BY name)")
fun getFirst(): LiveData<List<WallpaperData>>
@Query("SELECT * FROM wallpapers WHERE isLike = 1")
fun getLike(): LiveData<List<WallpaperData>>
@Query("SELECT * FROM wallpapers WHERE name = :name")
fun getAllCategory(name: String): LiveData<List<WallpaperData>>
@Query("SELECT isLike FROM wallpapers WHERE source = :imagePath")
fun getWallpaperLike(imagePath: String): LiveData<Boolean>
@Query("UPDATE wallpapers SET isLike = :isLike WHERE source = :imagePath")
suspend fun updateIsLike(imagePath: String, isLike: Boolean)
}

View File

@ -0,0 +1,15 @@
package com.wallpaper.wallpaperdream.data.database.entity
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "wallpapers")
data class WallpaperData(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
val name: String,
val original: String,
val previewThumb: String,
val source: String,
var isLike: Boolean
)

View File

@ -0,0 +1,50 @@
package com.wallpaper.wallpaperdream.data.repository
import android.content.Context
import androidx.lifecycle.LiveData
import com.wallpaper.wallpaperdream.data.database.AppDatabase
import com.wallpaper.wallpaperdream.data.database.dao.WallpaperDataDao
import com.wallpaper.wallpaperdream.data.database.entity.WallpaperData
class WallpaperRepository(context: Context) {
private val dao: WallpaperDataDao
init {
val appDatabase: AppDatabase = AppDatabase.getInstance(context)
dao = appDatabase.wallpaperDataDao()
}
suspend fun insertAll(wallpaperList: List<WallpaperData>) {
dao.insertAll(wallpaperList)
}
suspend fun updateWallpaper(wallpaper: WallpaperData) {
dao.update(wallpaper)
}
suspend fun updateIsLike(imagePath: String, isLike: Boolean) {
dao.updateIsLike(imagePath, isLike)
}
fun getWallpapers(limit: Int, offset: Int): LiveData<List<WallpaperData>> {
return dao.getWallpapers(limit, offset)
}
fun getFirst(): LiveData<List<WallpaperData>> {
return dao.getFirst()
}
fun getLike(): LiveData<List<WallpaperData>> {
return dao.getLike()
}
fun getAllCategory(name: String): LiveData<List<WallpaperData>> {
return dao.getAllCategory(name)
}
fun getWallpaperLike(imagePath: String): LiveData<Boolean> {
return dao.getWallpaperLike(imagePath)
}
}

View File

@ -0,0 +1,70 @@
package com.wallpaper.wallpaperdream.ui.activity
import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import com.wallpaper.wallpaperdream.R
import com.wallpaper.wallpaperdream.databinding.ActivityCategoryBinding
import com.wallpaper.wallpaperdream.ui.adapter.ImageAdapter
import com.wallpaper.wallpaperdream.utils.ItemDecoration
import com.wallpaper.wallpaperdream.viewmodel.WallpaperViewModel
class CategoryActivity : AppCompatActivity() {
private lateinit var binding: ActivityCategoryBinding
private lateinit var adapter: ImageAdapter
private lateinit var name: String
private lateinit var viewModel: WallpaperViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.enableEdgeToEdge()
binding = ActivityCategoryBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(
findViewById(R.id.main)
) { v: View, insets: WindowInsetsCompat ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
initData()
initEvent()
}
private fun initData() {
name = intent.getStringExtra("name").toString()
viewModel = ViewModelProvider(this)[WallpaperViewModel::class.java]
binding.recyclerView.setLayoutManager(GridLayoutManager(this, 2))
adapter = ImageAdapter(viewModel, this, ArrayList(), this)
binding.recyclerView.setAdapter(adapter)
val itemDecoration: ItemDecoration = ItemDecoration(16, 19, 20)
binding.recyclerView.addItemDecoration(itemDecoration)
}
private fun initEvent() {
binding.back.setOnClickListener { finish() }
binding.text.text = name
loadImage()
}
private fun loadImage() {
viewModel
.getAllCategory(name)
.observe(this, Observer { wallpapers ->
adapter.updateData(wallpapers)
})
}
}

View File

@ -0,0 +1,277 @@
package com.wallpaper.wallpaperdream.ui.activity
import android.app.WallpaperManager
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.wallpaper.wallpaperdream.R
import com.wallpaper.wallpaperdream.databinding.ActivityImageBinding
import com.wallpaper.wallpaperdream.utils.GallerySaver
import com.wallpaper.wallpaperdream.utils.GallerySaver.REQUEST_CODE_WRITE_EXTERNAL_STORAGE
import com.wallpaper.wallpaperdream.viewmodel.WallpaperViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class ImageActivity : AppCompatActivity() {
private lateinit var binding: ActivityImageBinding
private lateinit var imagePath: String
private lateinit var bitmap: Bitmap
private var isFavorite = false
private lateinit var gallerySaver: GallerySaver
private lateinit var wallpaperManager: WallpaperManager
private lateinit var viewModel: WallpaperViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.enableEdgeToEdge()
binding = ActivityImageBinding.inflate(layoutInflater)
setContentView(binding.getRoot())
ViewCompat.setOnApplyWindowInsetsListener(
findViewById(R.id.main)
) { v: View, insets: WindowInsetsCompat ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
initData()
initEvent()
}
private fun initData() {
imagePath = intent.getStringExtra("imagePath").toString()
viewModel = ViewModelProvider(this)[WallpaperViewModel::class.java]
gallerySaver = GallerySaver(this, binding.progressBar, binding.view)
wallpaperManager = WallpaperManager.getInstance(this)
}
private fun initEvent() {
showProgress()
binding.back.setOnClickListener { finish() }
binding.favorite.setOnClickListener {
isFavorite = !isFavorite
viewModel.updateIsLike(imagePath, isFavorite)
}
binding.setWallpaper.setOnClickListener { v -> showCustomBottomSheetDialog() }
binding.download.setOnClickListener { v ->
showProgress()
val activity = v.context as ImageActivity
gallerySaver.saveToGallery(activity, imagePath)
}
loadImage()
loadFavorite()
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_CODE_WRITE_EXTERNAL_STORAGE) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
gallerySaver.saveToGallery(this, imagePath)
} else {
Toast.makeText(
this,
"Description The write permission to the external storage is denied",
Toast.LENGTH_SHORT
).show()
}
}
}
private fun showCustomBottomSheetDialog() {
val bottomSheetDialog = BottomSheetDialog(this)
val dialogView: View = LayoutInflater.from(this).inflate(R.layout.set_dialog, null)
dialogView.findViewById<View>(R.id.both).setOnClickListener { v: View? ->
showProgress()
setWallpaperBoth(bitmap)
bottomSheetDialog.dismiss()
}
dialogView.findViewById<View>(R.id.lock).setOnClickListener { v: View? ->
showProgress()
setWallpaperLock(bitmap)
bottomSheetDialog.dismiss()
}
dialogView.findViewById<View>(R.id.desktop).setOnClickListener { v: View? ->
showProgress()
setWallpaperDeskTop(bitmap)
bottomSheetDialog.dismiss()
}
bottomSheetDialog.setContentView(dialogView)
bottomSheetDialog.show()
}
private fun setWallpaperBoth(bitmap: Bitmap) {
lifecycleScope.launch {
try {
withContext(Dispatchers.IO) {
wallpaperManager.let { wm ->
binding.image.setDrawingCacheEnabled(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wm.setBitmap(bitmap, null, true, WallpaperManager.FLAG_SYSTEM)
wm.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK)
} else {
wm.setBitmap(bitmap)
}
}
}
withContext(Dispatchers.Main) {
hideProgress()
binding.setWallpaper.isEnabled = true
Toast.makeText(applicationContext, "Wallpaper setting is successful", Toast.LENGTH_SHORT).show()
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
hideProgress()
Toast.makeText(applicationContext, "Failed to set wallpaper", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun setWallpaperLock(bitmap: Bitmap) {
lifecycleScope.launch {
try {
withContext(Dispatchers.IO) {
binding.image.setDrawingCacheEnabled(true)
wallpaperManager.let { wm ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wm.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK)
} else {
wm.setBitmap(bitmap)
}
}
}
withContext(Dispatchers.Main) {
hideProgress()
binding.setWallpaper.isEnabled = true
Toast.makeText(applicationContext, "Wallpaper setting is successful", Toast.LENGTH_SHORT).show()
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
hideProgress()
Toast.makeText(applicationContext, "Failed to set wallpaper", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun setWallpaperDeskTop(bitmap: Bitmap) {
lifecycleScope.launch {
try {
withContext(Dispatchers.IO) {
binding.image.setDrawingCacheEnabled(true)
wallpaperManager.let { wm ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wm.setBitmap(bitmap, null, true, WallpaperManager.FLAG_SYSTEM)
} else {
wm.setBitmap(bitmap)
}
}
}
withContext(Dispatchers.Main) {
hideProgress()
binding.setWallpaper.isEnabled = true
Toast.makeText(applicationContext, "Wallpaper setting is successful", Toast.LENGTH_SHORT).show()
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
hideProgress()
Toast.makeText(applicationContext, "Failed to set wallpaper", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun loadImage() {
Glide.with(this)
.asBitmap()
.load(imagePath)
.error(R.mipmap.placeholder)
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
binding.image.setImageBitmap(resource)
bitmap = resource
hideProgress()
}
override fun onLoadCleared(placeholder: Drawable?) {
binding.image.setImageDrawable(placeholder)
}
override fun onLoadFailed(errorDrawable: Drawable?) {
super.onLoadFailed(errorDrawable)
binding.image.setImageDrawable(errorDrawable ?: resources.getDrawable(R.mipmap.placeholder,null))
hideProgress()
}
})
}
private fun loadFavorite() {
viewModel
.getWallpaperLike(imagePath)
.observe(this, Observer { isLike ->
isFavorite = isLike;
setFavoriteButton()
})
}
private fun setFavoriteButton() {
binding.favorite.setImageResource(
if (isFavorite)
R.drawable.like
else
R.drawable.un_like
)
}
private fun hideProgress() {
binding.progressBar.visibility = View.GONE
binding.view.setVisibility(View.GONE)
}
private fun showProgress() {
binding.progressBar.visibility = View.VISIBLE
binding.view.setVisibility(View.VISIBLE)
}
}

View File

@ -0,0 +1,128 @@
package com.wallpaper.wallpaperdream.ui.activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import com.google.android.material.tabs.TabLayoutMediator
import com.wallpaper.wallpaperdream.R
import com.wallpaper.wallpaperdream.databinding.ActivityMainBinding
import com.wallpaper.wallpaperdream.databinding.MainCustomBinding
import com.wallpaper.wallpaperdream.ui.adapter.MainAdapter
import com.wallpaper.wallpaperdream.ui.fragment.CategoryFragment
import com.wallpaper.wallpaperdream.ui.fragment.FavoriteFragment
import com.wallpaper.wallpaperdream.ui.fragment.HomeFragment
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.enableEdgeToEdge()
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(
findViewById(R.id.main)
) { v: View, insets: WindowInsetsCompat ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
initData()
initEvent()
}
private fun initData() {
val fragmentList: MutableList<Fragment> = ArrayList()
fragmentList.add(HomeFragment())
fragmentList.add(CategoryFragment())
fragmentList.add(FavoriteFragment())
val adapter: MainAdapter = MainAdapter(this, fragmentList)
binding.mainViewpager.setAdapter(adapter)
}
private fun initEvent() {
binding.mainViewpager.setUserInputEnabled(false)
TabLayoutMediator(
binding.mainTablayout,
binding.mainViewpager
) { tab: TabLayout.Tab, position: Int ->
val tabBinding: MainCustomBinding =
MainCustomBinding.inflate(LayoutInflater.from(this))
tab.setCustomView(tabBinding.getRoot())
setTabIconAndDotVisibility(tabBinding, position)
}.attach()
binding.mainTablayout.addOnTabSelectedListener(object : OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
updateTabIcon(tab, true)
showDot(tab)
}
override fun onTabUnselected(tab: TabLayout.Tab) {
updateTabIcon(tab, false)
hideDot(tab)
}
override fun onTabReselected(tab: TabLayout.Tab) {
}
fun updateTabIcon(tab: TabLayout.Tab, isSelected: Boolean) {
tab.customView?.let { customView ->
val tabBinding: MainCustomBinding = MainCustomBinding.bind(customView)
val iconResId = getIconResource(tab.position, isSelected)
tabBinding.iconCustom.setImageResource(iconResId)
}
}
fun getIconResource(position: Int, isSelected: Boolean): Int {
return when (position) {
1 -> R.drawable.category
2 -> R.drawable.favorite
else -> R.drawable.home
}
}
})
}
private fun setTabIconAndDotVisibility(tabBinding: MainCustomBinding, position: Int) {
when (position) {
0 -> {
tabBinding.iconCustom.setImageResource(R.drawable.home)
tabBinding.dotView.visibility = View.VISIBLE
}
1 -> tabBinding.iconCustom.setImageResource(R.drawable.category)
2 -> tabBinding.iconCustom.setImageResource(R.drawable.favorite)
else -> tabBinding.iconCustom.setImageResource(R.drawable.home)
}
}
private fun showDot(tab: TabLayout.Tab) {
val dotView = tab.view.findViewById<View>(R.id.dot_view)
if (dotView != null) {
dotView.visibility = View.VISIBLE
}
}
private fun hideDot(tab: TabLayout.Tab) {
val dotView = tab.view.findViewById<View>(R.id.dot_view)
if (dotView != null) {
dotView.visibility = View.GONE
}
}
}

View File

@ -0,0 +1,83 @@
package com.wallpaper.wallpaperdream.ui.adapter
import android.app.Activity
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 android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.wallpaper.wallpaperdream.R
import com.wallpaper.wallpaperdream.data.database.entity.WallpaperData
import com.wallpaper.wallpaperdream.ui.activity.CategoryActivity
class CategoryAdapter(
private val context: Context,
imageEntries: List<WallpaperData>,
activity: Activity
) :
RecyclerView.Adapter<CategoryAdapter.ViewHolder>() {
private var imageEntries: List<WallpaperData>
private val activity: Activity
init {
this.imageEntries = imageEntries
this.activity = activity
}
fun updateData(newFavoriteImages: List<WallpaperData>) {
this.imageEntries = newFavoriteImages
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view: View = LayoutInflater.from(context).inflate(R.layout.item_category, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val imageEntry: WallpaperData = imageEntries[position]
holder.bind(imageEntry)
}
override fun getItemCount(): Int {
return imageEntries.size
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private var imageView: ImageView = itemView.findViewById(R.id.imageview)
private var textView: TextView = itemView.findViewById(R.id.category_title)
fun bind(imageEntry: WallpaperData) {
val imageEntryOriginal: String = imageEntry.original
textView.text = imageEntry.name
loadImage(imageEntryOriginal)
setClickListeners(imageEntry)
}
private fun loadImage(imageEntryOriginal: String) {
Glide.with(context)
.load(imageEntryOriginal)
.transform(RoundedCorners(32))
.error(R.mipmap.placeholder)
.placeholder(R.mipmap.placeholder)
.into(imageView)
}
private fun setClickListeners(imageEntry: WallpaperData) {
imageView.setOnClickListener { v: View? ->
val intent = Intent(
activity,
CategoryActivity::class.java
)
intent.putExtra("name", imageEntry.name)
activity.startActivity(intent)
}
}
}
}

View File

@ -0,0 +1,18 @@
package com.wallpaper.wallpaperdream.ui.adapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.wallpaper.wallpaperdream.ui.fragment.HomeCategoryFragment
class HomeFragmentAdapter(fragmentActivity: FragmentActivity, private val types: IntArray) :
FragmentStateAdapter(fragmentActivity) {
override fun createFragment(position: Int): Fragment {
val type = types[position]
return HomeCategoryFragment.newInstance(type)
}
override fun getItemCount(): Int {
return types.size
}
}

View File

@ -0,0 +1,110 @@
package com.wallpaper.wallpaperdream.ui.adapter
import android.app.Activity
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
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.wallpaper.wallpaperdream.R
import com.wallpaper.wallpaperdream.data.database.AppDatabase
import com.wallpaper.wallpaperdream.data.database.entity.WallpaperData
import com.wallpaper.wallpaperdream.ui.activity.ImageActivity
import com.wallpaper.wallpaperdream.viewmodel.WallpaperViewModel
import java.util.concurrent.Executor
import java.util.concurrent.Executors
class ImageAdapter(
private val viewModel: WallpaperViewModel,
private val context: Context,
imageEntries: List<WallpaperData>,
activity: Activity
) :
RecyclerView.Adapter<ImageAdapter.ViewHolder>() {
private var imageEntries: List<WallpaperData>
private val activity: Activity
init {
this.imageEntries = imageEntries
this.activity = activity
}
fun updateData(newFavoriteImages: List<WallpaperData>) {
this.imageEntries = newFavoriteImages
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view: View = LayoutInflater.from(context).inflate(R.layout.item_image, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val imageEntry: WallpaperData = imageEntries[position]
holder.bind(imageEntry)
}
override fun getItemCount(): Int {
return imageEntries.size
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private var imageView: ImageView = itemView.findViewById(R.id.image_view)
private var favoriteButton: ImageView = itemView.findViewById(R.id.btn_favorite)
fun bind(imageEntry: WallpaperData) {
val imageEntryOriginal: String = imageEntry.original
loadImage(imageEntryOriginal)
setFavoriteButton(imageEntry)
setClickListeners(imageEntry)
}
private fun loadImage(imageEntryOriginal: String) {
Glide.with(context)
.load(imageEntryOriginal)
.transform(RoundedCorners(16))
.error(R.mipmap.placeholder)
.placeholder(R.mipmap.placeholder)
.into(imageView)
}
private fun setFavoriteButton(imageEntry: WallpaperData) {
favoriteButton.setImageResource(
if (imageEntry.isLike)
R.drawable.like
else
R.drawable.un_like
)
}
private fun setClickListeners(imageEntry: WallpaperData) {
imageView.setOnClickListener {
val intent = Intent(
activity,
ImageActivity::class.java
)
intent.putExtra("imagePath", imageEntry.source)
activity.startActivity(intent)
}
favoriteButton.setOnClickListener { toggleFavorite(imageEntry) }
}
private fun toggleFavorite(imageEntry: WallpaperData) {
val newStatus: Boolean = !imageEntry.isLike
imageEntry.isLike = newStatus
updateImageInDatabase(imageEntry)
notifyItemChanged(adapterPosition)
}
private fun updateImageInDatabase(imageEntry: WallpaperData) {
viewModel.updateWallpaper(imageEntry)
}
}
}

View File

@ -0,0 +1,19 @@
package com.wallpaper.wallpaperdream.ui.adapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
class MainAdapter(
fragmentActivity: FragmentActivity,
private val fragmentList: List<Fragment>
) :
FragmentStateAdapter(fragmentActivity) {
override fun createFragment(position: Int): Fragment {
return fragmentList[position]
}
override fun getItemCount(): Int {
return fragmentList.size
}
}

View File

@ -0,0 +1,59 @@
package com.wallpaper.wallpaperdream.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.wallpaper.wallpaperdream.databinding.FragmentCategoryBinding
import com.wallpaper.wallpaperdream.ui.adapter.CategoryAdapter
import com.wallpaper.wallpaperdream.ui.adapter.ImageAdapter
import com.wallpaper.wallpaperdream.utils.ItemDecoration
import com.wallpaper.wallpaperdream.viewmodel.WallpaperViewModel
class CategoryFragment : Fragment() {
private lateinit var binding: FragmentCategoryBinding
private lateinit var adapter: CategoryAdapter
private lateinit var viewModel: WallpaperViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentCategoryBinding.inflate(inflater, container, false)
initData()
initEvent()
return binding.root
}
private fun initData() {
viewModel = ViewModelProvider(this)[WallpaperViewModel::class.java]
binding.recyclerView.setLayoutManager(LinearLayoutManager(context))
adapter = CategoryAdapter(requireContext(), ArrayList(), requireActivity())
binding.recyclerView.setAdapter(adapter)
val itemDecoration: ItemDecoration = ItemDecoration(0, 19, 0)
binding.recyclerView.addItemDecoration(itemDecoration)
}
private fun initEvent() {
loadCategoryImage()
}
private fun loadCategoryImage() {
viewModel
.getFirst()
.observe(viewLifecycleOwner, Observer { wallpapers ->
adapter.updateData(wallpapers)
})
}
}

View File

@ -0,0 +1,62 @@
package com.wallpaper.wallpaperdream.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import com.wallpaper.wallpaperdream.databinding.FragmentFavoriteBinding
import com.wallpaper.wallpaperdream.ui.adapter.ImageAdapter
import com.wallpaper.wallpaperdream.utils.ItemDecoration
import com.wallpaper.wallpaperdream.viewmodel.WallpaperViewModel
class FavoriteFragment : Fragment() {
private lateinit var binding: FragmentFavoriteBinding
private lateinit var adapter: ImageAdapter
private lateinit var viewModel: WallpaperViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentFavoriteBinding.inflate(inflater, container, false)
initData()
initEvent()
return binding.root
}
private fun initData() {
viewModel = ViewModelProvider(this)[WallpaperViewModel::class.java]
binding.recyclerView.setLayoutManager(GridLayoutManager(context, 2))
adapter = ImageAdapter(viewModel, requireContext(), ArrayList(), requireActivity())
binding.recyclerView.setAdapter(adapter)
val itemDecoration: ItemDecoration = ItemDecoration(16, 19, 20)
binding.recyclerView.addItemDecoration(itemDecoration)
}
private fun initEvent() {
loadFavoriteImages()
}
private fun loadFavoriteImages() {
viewModel
.getLike()
.observe(viewLifecycleOwner, Observer { wallpapers ->
if (wallpapers.isEmpty()) {
binding.backgroundText.visibility = View.VISIBLE
} else {
binding.backgroundText.visibility = View.GONE
}
adapter.updateData(wallpapers)
})
}
}

View File

@ -0,0 +1,78 @@
package com.wallpaper.wallpaperdream.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import com.wallpaper.wallpaperdream.databinding.FragmentHomeCategoryBinding
import com.wallpaper.wallpaperdream.ui.adapter.ImageAdapter
import com.wallpaper.wallpaperdream.utils.ItemDecoration
import com.wallpaper.wallpaperdream.viewmodel.WallpaperViewModel
class HomeCategoryFragment : Fragment() {
private lateinit var binding: FragmentHomeCategoryBinding
private lateinit var viewModel: WallpaperViewModel
private lateinit var adapter: ImageAdapter
private var type = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (arguments != null) {
type = requireArguments().getInt(ARG_CATEGORY)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentHomeCategoryBinding.inflate(inflater, container, false)
initData()
initEvent()
return binding.root
}
private fun initData() {
viewModel = ViewModelProvider(this)[WallpaperViewModel::class.java]
binding.recyclerView.setLayoutManager(GridLayoutManager(context, 2))
adapter = ImageAdapter(viewModel, requireContext(), ArrayList(), requireActivity())
binding.recyclerView.setAdapter(adapter)
val itemDecoration: ItemDecoration = ItemDecoration(16, 19, 20)
binding.recyclerView.addItemDecoration(itemDecoration)
}
private fun initEvent() {
loadImages()
}
private fun loadImages() {
val randomOffset = (0..2000).random()
viewModel
.getWallpapers(type,randomOffset)
.observe(viewLifecycleOwner, Observer { wallpapers ->
adapter.updateData(wallpapers)
})
}
companion object {
private const val ARG_CATEGORY = "type"
fun newInstance(type: Int?): HomeCategoryFragment {
val fragment = HomeCategoryFragment()
val args = Bundle()
args.putInt(ARG_CATEGORY, type!!)
fragment.arguments = args
return fragment
}
}
}

View File

@ -0,0 +1,90 @@
package com.wallpaper.wallpaperdream.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import com.google.android.material.tabs.TabLayoutMediator
import com.wallpaper.wallpaperdream.R
import com.wallpaper.wallpaperdream.databinding.FragmentHomeBinding
import com.wallpaper.wallpaperdream.databinding.ItemHomeCategoryBinding
import com.wallpaper.wallpaperdream.ui.adapter.HomeFragmentAdapter
class HomeFragment : Fragment() {
private lateinit var binding: FragmentHomeBinding
private val types = intArrayOf(1, 2, 3)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentHomeBinding.inflate(inflater, container, false)
initData()
initEvent()
return binding.root
}
private fun initData() {
val adapter: HomeFragmentAdapter = HomeFragmentAdapter(requireActivity(), types)
binding.viewpager.setAdapter(adapter)
}
private fun initEvent() {
TabLayoutMediator(
binding.tablayout,
binding.viewpager
) { tab: TabLayout.Tab, position: Int ->
val tabBinding: ItemHomeCategoryBinding =
ItemHomeCategoryBinding.inflate(LayoutInflater.from(requireContext()))
tab.setCustomView(tabBinding.getRoot())
setTabIconAndDotVisibility(tabBinding, position)
}.attach()
binding.tablayout.addOnTabSelectedListener(object : OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
updateTabIcon(tab, true)
}
override fun onTabUnselected(tab: TabLayout.Tab) {
updateTabIcon(tab, false)
}
override fun onTabReselected(tab: TabLayout.Tab) {
}
fun updateTabIcon(tab: TabLayout.Tab, isSelected: Boolean) {
tab.customView?.let { customView ->
val tabBinding: ItemHomeCategoryBinding =
ItemHomeCategoryBinding.bind(customView)
val textColor = getTextColor(isSelected)
tabBinding.text.setTextColor(resources.getColor(textColor, null))
}
}
fun getTextColor(isSelected: Boolean): Int {
return if (isSelected) R.color.black else R.color.gray
}
})
}
private fun setTabIconAndDotVisibility(tabBinding: ItemHomeCategoryBinding, position: Int) {
when (position) {
0 -> {
tabBinding.text.text = getString(R.string.Suggested)
tabBinding.text.setTextColor(resources.getColor(R.color.black, null))
}
1 -> tabBinding.text.text = getString(R.string.Trending)
2 -> tabBinding.text.text = getString(R.string.Surprise)
}
}
}

View File

@ -0,0 +1,145 @@
package com.wallpaper.wallpaperdream.utils;
import android.Manifest;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class GallerySaver {
public static final int REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 123;
private final ProgressBar progressBar;
private final ImageView overlayView;
public GallerySaver(Context context, ProgressBar progressBar, ImageView overlayView) {
this.progressBar = progressBar;
this.overlayView = overlayView;
}
public void saveToGallery(Activity activity, String imageUrl) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
new SaveImageTask(activity, progressBar).execute(imageUrl);
} else {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_WRITE_EXTERNAL_STORAGE);
} else {
new SaveImageTask(activity, progressBar).execute(imageUrl);
}
}
}
private class SaveImageTask extends AsyncTask<String, Void, Uri> {
private final Activity activity;
private final ProgressBar progressBar;
public SaveImageTask(Activity activity, ProgressBar progressBar) {
this.activity = activity;
this.progressBar = progressBar;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
if (progressBar != null) {
progressBar.setVisibility(View.VISIBLE);
}
}
@Override
protected Uri doInBackground(String... params) {
String imageUrl = params[0];
String displayName = System.currentTimeMillis() + ".jpg";
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, displayName);
contentValues.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
contentValues.put(MediaStore.Images.Media.IS_PENDING, 1);
}
Uri collectionUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
collectionUri = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
} else {
collectionUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
}
Uri imageUri = activity.getContentResolver().insert(collectionUri, contentValues);
if (imageUri != null) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL(imageUrl).openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream = connection.getInputStream();
try (OutputStream outputStream = activity.getContentResolver().openOutputStream(imageUri)) {
if (outputStream != null) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
} finally {
inputStream.close();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
contentValues.clear();
contentValues.put(MediaStore.Images.Media.IS_PENDING, 0);
activity.getContentResolver().update(imageUri, contentValues, null, null);
}
return imageUri;
} catch (IOException e) {
Log.e("GallerySaver", "Error saving image to gallery", e);
activity.getContentResolver().delete(imageUri, null, null);
return null;
}
} else {
Log.e("GallerySaver", "Failed to insert image into MediaStore");
return null;
}
}
@Override
protected void onPostExecute(Uri uri) {
super.onPostExecute(uri);
if (progressBar != null && overlayView != null) {
progressBar.setVisibility(View.GONE);
overlayView.setVisibility(View.GONE);
}
if (uri != null) {
Toast.makeText(activity, "Image downloaded", Toast.LENGTH_SHORT).show();
Log.d("GallerySaver", "Image saved to gallery: " + uri);
} else {
Toast.makeText(activity, "StaticValue.key_download_failure", Toast.LENGTH_SHORT).show();
Log.e("GallerySaver", "Download failure");
}
}
}
}

View File

@ -0,0 +1,76 @@
package com.wallpaper.wallpaperdream.utils;
import android.graphics.Rect;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.wallpaper.wallpaperdream.MyApplication;
public class ItemDecoration extends RecyclerView.ItemDecoration {
private final int v;
private final int h;
private final int ex;
public ItemDecoration(int v, int h, int ex) {
this.v = Math.round(dpToPx(v));
this.h = Math.round(dpToPx(h));
this.ex = Math.round(dpToPx(ex));
}
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
int spanCount = 1;
int spanSize = 1;
int spanIndex = 0;
int childAdapterPosition = parent.getChildAdapterPosition(view);
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
spanCount = staggeredGridLayoutManager.getSpanCount();
if (layoutParams.isFullSpan()) {
spanSize = spanCount;
}
spanIndex = layoutParams.getSpanIndex();
} else if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
spanCount = gridLayoutManager.getSpanCount();
spanSize = gridLayoutManager.getSpanSizeLookup().getSpanSize(childAdapterPosition);
spanIndex = layoutParams.getSpanIndex();
} else if (layoutManager instanceof LinearLayoutManager) {
outRect.left = v;
outRect.right = v;
outRect.bottom = h;
}
if (spanSize == spanCount) {
outRect.left = v + ex;
outRect.right = v + ex;
} else {
int itemAllSpacing = (v * (spanCount + 1) + ex * 2) / spanCount;
int left = v * (spanIndex + 1) - itemAllSpacing * spanIndex + ex;
int right = itemAllSpacing - left;
outRect.left = left;
outRect.right = right;
}
outRect.bottom = h;
}
public static float dpToPx(float dpValue) {
float density = MyApplication.getContext().getResources().getDisplayMetrics().density;
return density * dpValue + 0.5f;
}
}

View File

@ -0,0 +1,71 @@
package com.wallpaper.wallpaperdream.utils
import com.wallpaper.wallpaperdream.MyApplication
import com.wallpaper.wallpaperdream.data.database.entity.WallpaperData
import org.json.JSONArray
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
object JsonUtils {
private fun loadJSONFromAsset(fileName: String): String {
val jsonString = StringBuilder()
try {
MyApplication.getContext().assets.open(fileName).use { inputStream ->
BufferedReader(InputStreamReader(inputStream)).use { reader ->
reader.forEachLine { line ->
jsonString.append(line)
}
}
}
} catch (e: IOException) {
e.printStackTrace()
}
return jsonString.toString()
}
fun parseJson(fileName: String): List<WallpaperData> {
val audioDataList = mutableListOf<WallpaperData>()
try {
val jsonString = loadJSONFromAsset(fileName)
if (jsonString.isEmpty()) {
throw IllegalArgumentException("JSON file is empty or invalid.")
}
val jsonArray = JSONArray(jsonString)
for (i in 0 until jsonArray.length()) {
val categoryObject = jsonArray.getJSONObject(i)
val name = categoryObject.getString("name")
val listArray = categoryObject.getJSONArray("data")
for (j in 0 until listArray.length()) {
val itemObject = listArray.getJSONObject(j)
val original = itemObject.getString("original")
val previewThumb = itemObject.getString("previewThumb")
val source = itemObject.getString("source")
audioDataList.add(
WallpaperData(
name = name,
original = original,
previewThumb = previewThumb,
source = source,
isLike = false
)
)
}
}
} catch (e: Exception) {
e.printStackTrace()
}
return audioDataList
}
}

View File

@ -0,0 +1,54 @@
package com.wallpaper.wallpaperdream.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.wallpaper.wallpaperdream.data.database.entity.WallpaperData
import com.wallpaper.wallpaperdream.data.repository.WallpaperRepository
import kotlinx.coroutines.launch
class WallpaperViewModel(application: Application) : AndroidViewModel(application) {
private val repository: WallpaperRepository = WallpaperRepository(application)
fun updateWallpaper(wallpaper: WallpaperData) {
viewModelScope.launch {
repository.updateWallpaper(wallpaper)
}
}
fun updateIsLike(imagePath: String, isLike: Boolean) {
viewModelScope.launch {
repository.updateIsLike(imagePath, isLike)
}
}
fun getWallpapers(i: Int,random: Int): LiveData<List<WallpaperData>> {
return when (i) {
1 -> repository.getWallpapers(20, 20)
2 -> repository.getWallpapers(20, 50)
3 -> repository.getWallpapers(20, random)
else -> MutableLiveData()
}
}
fun getFirst(): LiveData<List<WallpaperData>> {
return repository.getFirst()
}
fun getLike(): LiveData<List<WallpaperData>> {
return repository.getLike()
}
fun getAllCategory(name: String): LiveData<List<WallpaperData>> {
return repository.getAllCategory(name)
}
fun getWallpaperLike(imagePath: String): LiveData<Boolean> {
return repository.getWallpaperLike(imagePath)
}
}

View File

@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M24,36L12,24L24,12"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="M36,36L24,24L36,12"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M18,6H8C6.895,6 6,6.895 6,8V18C6,19.105 6.895,20 8,20H18C19.105,20 20,19.105 20,18V8C20,6.895 19.105,6 18,6Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#FFEB3B"/>
<path
android:pathData="M18,28H8C6.895,28 6,28.895 6,30V40C6,41.105 6.895,42 8,42H18C19.105,42 20,41.105 20,40V30C20,28.895 19.105,28 18,28Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#FFEB3B"/>
<path
android:pathData="M40,6H30C28.895,6 28,6.895 28,8V18C28,19.105 28.895,20 30,20H40C41.105,20 42,19.105 42,18V8C42,6.895 41.105,6 40,6Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#FFEB3B"/>
<path
android:pathData="M40,28H30C28.895,28 28,28.895 28,30V40C28,41.105 28.895,42 30,42H40C41.105,42 42,41.105 42,40V30C42,28.895 41.105,28 40,28Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#FFEB3B"/>
</vector>

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="4dp"
android:height="4dp"
android:viewportWidth="4"
android:viewportHeight="4">
<group>
<clip-path
android:pathData="M0,0h4v4h-4z"/>
<path
android:pathData="M2,4C3.1046,4 4,3.1046 4,2C4,0.8954 3.1046,0 2,0C0.8954,0 0,0.8954 0,2C0,3.1046 0.8954,4 2,4Z"
android:fillColor="#2196F3"/>
</group>
</vector>

View File

@ -0,0 +1,41 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M11.678,20.271C7.275,21.318 4,25.277 4,30C4,35.523 8.477,40 14,40C14.947,40 15.864,39.868 16.733,39.622"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#333"
android:strokeLineCap="round"/>
<path
android:pathData="M36.055,20.271C40.458,21.318 43.732,25.277 43.732,30C43.732,35.523 39.255,40 33.732,40C32.785,40 31.868,39.868 31,39.622"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#333"
android:strokeLineCap="round"/>
<path
android:pathData="M36,20C36,13.373 30.627,8 24,8C17.373,8 12,13.373 12,20"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#333"
android:strokeLineCap="round"/>
<path
android:pathData="M17.065,30.119L24,37.076L31.132,30"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#333"
android:strokeLineCap="round"/>
<path
android:pathData="M24,20V33.538"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#333"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M43,23V14C43,12.895 42.105,12 41,12H24L19,6H7C5.895,6 5,6.895 5,8V40C5,41.105 5.895,42 7,42H22"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#FFEB3B"
android:strokeLineCap="round"/>
<path
android:pathData="M35,27L37.243,31.913L42.609,32.528L38.629,36.179L39.702,41.472L35,38.816L30.298,41.472L31.371,36.179L27.392,32.528L32.757,31.913L35,27Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#FFEB3B"
android:strokeColor="#FFEB3B"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M44,44V20L24,4L4,20L4,44H16V26H32V44H44Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#FFEB3B"
android:strokeColor="#FFEB3B"/>
<path
android:pathData="M24,44V34"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#FFEB3B"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M15,8C8.925,8 4,12.925 4,19C4,30 17,40 24,42.326C31,40 44,30 44,19C44,12.925 39.075,8 33,8C29.28,8 25.991,9.847 24,12.674C22.009,9.847 18.72,8 15,8Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#d0021b"
android:strokeColor="#d0021b"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/white"/>
</shape>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners
android:topLeftRadius="46dp"
android:bottomLeftRadius="46dp"
android:bottomRightRadius="46dp"
android:topRightRadius="46dp" />
</shape>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="@color/gray" />
<corners android:radius="6dp" />
</shape>

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M15,8C8.925,8 4,12.925 4,19C4,30 17,40 24,42.326C31,40 44,30 44,19C44,12.925 39.075,8 33,8C29.28,8 25.991,9.847 24,12.674C22.009,9.847 18.72,8 15,8Z"
android:strokeLineJoin="round"
android:strokeWidth="4"
android:fillColor="#00000000"
android:strokeColor="#d0021b"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activity.CategoryActivity">
<ImageView
android:id="@+id/back"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="25dp"
android:src="@drawable/back"
app:layout_constraintBottom_toBottomOf="@+id/text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/text" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray"
tools:context=".ui.activity.ImageActivity">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/back"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="25dp"
android:layout_marginTop="25dp"
android:src="@drawable/back"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/download"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="@drawable/rounded"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="@id/set_wallpaper"
app:layout_constraintEnd_toStartOf="@+id/set_wallpaper"
app:layout_constraintStart_toStartOf="parent">
<ProgressBar
android:id="@+id/download_progress"
android:layout_width="24dp"
android:layout_height="24dp"
android:indeterminateTint="@color/black"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/download"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/set_wallpaper"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginBottom="25dp"
android:background="@drawable/rounded_rectangle"
android:paddingStart="16dp"
android:paddingTop="10dp"
android:paddingEnd="16dp"
android:paddingBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ProgressBar
android:id="@+id/set_wallpaper_progress"
android:layout_width="20dp"
android:layout_height="20dp"
android:indeterminateTint="@color/black"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/set_wallpaper"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="@+id/favorite"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="@drawable/rounded"
android:padding="10dp"
android:src="@drawable/un_like"
app:layout_constraintBottom_toBottomOf="@+id/set_wallpaper"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/set_wallpaper" />
<ImageView
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray"
android:focusable="true"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activity.MainActivity">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/main_tablayout"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/main_tablayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:tabIndicatorHeight="0dp"
android:layout_marginBottom="25dp"
app:tabRippleColor="@android:color/transparent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragment.CategoryFragment">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="@string/Category"
android:textColor="@color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragment.FavoriteFragment">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="@string/Favorite"
android:textColor="@color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/background_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="@string/you_don_t_have_any_collection_yet"
android:textColor="@color/gray"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.fragment.HomeFragment">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="24sp"
android:text="@string/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="25dp"
android:background="@android:color/transparent"
app:layout_constraintTop_toBottomOf="@+id/text"
app:tabIndicatorHeight="0dp"
app:tabRippleColor="@android:color/transparent" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tablayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragment.HomeCategoryFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="250dp">
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/category_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/gray"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,21 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="144dp"
android:layout_height="256dp">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"/>
<ImageView
android:id="@+id/btn_favorite"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:src="@drawable/un_like"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/icon_custom"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<View
android:id="@+id/dot_view"
android:layout_width="5dp"
android:layout_height="5dp"
android:layout_marginTop="6dp"
android:background="@drawable/dot"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/icon_custom"
app:layout_constraintStart_toStartOf="@+id/icon_custom"
app:layout_constraintTop_toBottomOf="@+id/icon_custom" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text=""
android:textColor="@color/black"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/both"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:background="@drawable/set_dialog_background"
android:padding="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/both"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/lock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:layout_marginBottom="20dp"
android:background="@drawable/set_dialog_background"
android:padding="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/both">
<TextView
android:id="@+id/lock_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lock"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/desktop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:layout_marginBottom="20dp"
android:background="@drawable/set_dialog_background"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/lock">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/desktop"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 KiB

View File

@ -0,0 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.WallpaperDream" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>
</resources>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="gray">#9C979D</color>
</resources>

View File

@ -0,0 +1,16 @@
<resources>
<string name="app_name">Wallpaper Dream</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="Suggested">SUGGESTED</string>
<string name="Trending">TRENDING</string>
<string name="Surprise">SURPRISE</string>
<string name="Category">Category</string>
<string name="Favorite">Favorite</string>
<string name="set_wallpaper">Set Wallpaper</string>
<string name="set_as_wallpaper">Set as wallpaper</string>
<string name="both">Both</string>
<string name="lock">Lock</string>
<string name="desktop">Desktop</string>
<string name="you_don_t_have_any_collection_yet">You don\'t have any collection yet</string>
</resources>

View File

@ -0,0 +1,9 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.WallpaperDream" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>
<style name="Theme.WallpaperDream" parent="Base.Theme.WallpaperDream" />
</resources>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample backup rules file; uncomment and customize as necessary.
See https://developer.android.com/guide/topics/data/autobackup
for details.
Note: This file is ignored for devices older that API 31
See https://developer.android.com/about/versions/12/backup-restore
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->
</full-backup-content>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!-- TODO: Use <include> and <exclude> to control what is backed up.
<include .../>
<exclude .../>
-->
</cloud-backup>
<!--
<device-transfer>
<include .../>
<exclude .../>
</device-transfer>
-->
</data-extraction-rules>

View File

@ -0,0 +1,17 @@
package com.wallpaper.wallpaperdream
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

5
build.gradle.kts Normal file
View File

@ -0,0 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
}

23
gradle.properties Normal file
View File

@ -0,0 +1,23 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true

26
gradle/libs.versions.toml Normal file
View File

@ -0,0 +1,26 @@
[versions]
agp = "8.7.3"
kotlin = "1.9.24"
coreKtx = "1.10.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.10.0"
activity = "1.8.0"
constraintlayout = "2.1.4"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
#Mon Dec 30 15:58:34 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
gradlew vendored Normal file
View File

@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

89
gradlew.bat vendored Normal file
View File

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

24
settings.gradle.kts Normal file
View File

@ -0,0 +1,24 @@
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "Wallpaper Dream"
include(":app")