Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rajaumair7890 committed May 23, 2024
0 parents commit 1dcecc7
Show file tree
Hide file tree
Showing 101 changed files with 2,120 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
72 changes: 72 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
}

android {
namespace = "com.codingwithumair.app.darklify"
compileSdk = 34

defaultConfig {
applicationId = "com.codingwithumair.app.darklify"
minSdk = 30
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {

implementation(libs.coil.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Binary file added app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.codingwithumair.app.darklify

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.codingwithumair.app.darklify", appContext.packageName)
}
}
52 changes: 52 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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.SET_WALLPAPER" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:name=".DarklifyApp"
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.Darklify"
tools:targetApi="34">

<receiver
android:name=".bootCompleted.BootCompletedReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Darklify">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<service
android:name=".MainService"
android:foregroundServiceType="specialUse" />

</application>

</manifest>
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions app/src/main/java/com/codingwithumair/app/darklify/DarklifyApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codingwithumair.app.darklify

import android.app.Application
import com.codingwithumair.app.darklify.data.AppContainer

class DarklifyApp: Application() {

lateinit var container: AppContainer
override fun onCreate() {
super.onCreate()
container = AppContainer(this)
}
}
100 changes: 100 additions & 0 deletions app/src/main/java/com/codingwithumair/app/darklify/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.codingwithumair.app.darklify

import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import com.codingwithumair.app.darklify.ui.mainScreen.MainScreen
import com.codingwithumair.app.darklify.ui.mainScreen.MainViewModel
import com.codingwithumair.app.darklify.ui.mainScreen.components.WallpaperSettingDialog
import com.codingwithumair.app.darklify.ui.theme.DarklifyTheme
import com.codingwithumair.app.darklify.utils.WallpaperUtils
import kotlinx.coroutines.delay

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val permission = checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)
if(permission == PackageManager.PERMISSION_DENIED){
requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), 0)
}
}
setContent {
DarklifyTheme {

var showDialog by remember {
mutableStateOf(false)
}

LaunchedEffect(key1 = showDialog) {
delay(5000)
showDialog = false
}

Box(
modifier = Modifier.fillMaxSize()
) {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {

val viewModel: MainViewModel = viewModel(factory = MainViewModel.factory)
val uiState by viewModel.uiState.collectAsState()

val application = remember {
this@MainActivity.application as DarklifyApp
}

val darkMode = isSystemInDarkTheme()

LaunchedEffect(key1 = uiState.enabled) {
delay(300) // It takes some time to read values from dataStore
val shouldStartService = uiState.enabled
MainService.startOrStopService(this@MainActivity, shouldStartService)
}

MainScreen(
enabled = uiState.enabled,
onEnabledChange = viewModel::updateEnabled,
lightWallpaperBitmap = uiState.lightWallpaperBitmap,
darkWallpaperBitmap = uiState.darkWallpaperBitmap,
onLightWallpaperChange = viewModel::updateLightWallpaper,
onDarkWallpaperChange = viewModel::updateDarkWallpaper,
listOfWallpapers = viewModel.wallpaperPairsList,
selectedItem = uiState.selectedItem,
onSelectedItemChange = {
showDialog = true
WallpaperUtils.changeWallpaper(application, darkMode, it)
viewModel.updateSelectedItem(it)
}
)
}

if(showDialog){
WallpaperSettingDialog()
}
}
}
}
}
}

Loading

0 comments on commit 1dcecc7

Please sign in to comment.