Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
New : Auto Wallpaper working
Browse files Browse the repository at this point in the history
  • Loading branch information
DawnImpulse committed Jul 21, 2019
1 parent f23c16a commit 8671758
Show file tree
Hide file tree
Showing 43 changed files with 204 additions and 124 deletions.
74 changes: 36 additions & 38 deletions app/app.iml

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

kotlinOptions {
jvmTarget = "1.8"
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand All @@ -43,33 +53,34 @@ dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
//--------------- Support Libraries ---------------------
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation "androidx.core:core-ktx:1.0.2"
implementation "androidx.work:work-runtime-ktx:2.0.1"
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.core:core-ktx:1.1.0-rc02'
implementation "androidx.work:work-runtime-ktx:2.1.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
implementation "androidx.concurrent:concurrent-futures:1.0.0-beta01"
implementation "androidx.preference:preference:1.1.0-beta01"
implementation "androidx.preference:preference:1.1.0-rc01"

implementation "com.google.android.material:material:1.0.0"

//--------------- Firebase Libraries --------------------
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

//--------------- 3rd Party Libraries -------------------
implementation 'com.github.bumptech.glide:glide:4.9.0' // image loading
implementation 'com.squareup.retrofit2:retrofit:2.4.0' // retrofit
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0' // retrofit
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.0' //rx relay
implementation 'com.makeramen:roundedimageview:2.3.0' //rounding images
implementation 'com.github.chrisbanes:PhotoView:2.3.0' // photo view
implementation 'jp.wasabeef:blurry:3.0.0' //blur library
implementation 'commons-io:commons-io:2.4' // apache commons io
implementation 'commons-io:commons-io:2.6' // apache commons io
implementation 'org.sourcei.android:permissions:1.0.1' //permissions
implementation 'co.revely:gradient:1.0.1' // gradient
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.12.0' // tap target

//------------------ Additional -------------------------
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-RC'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
android:label="Wallup"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute,MissingApplicationIcon">
Expand Down Expand Up @@ -58,7 +57,7 @@
<activity
android:name=".ui.activities.SettingsActivity"
android:label="Settings"
android:theme="@style/AppTheme.Fullscreen" />
android:theme="@style/PrefsTheme" />

<!--Image Screen-->
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class HomescreenActivity : AppCompatActivity(), OnLoadMoreListener, SwipeRefresh
model.getHomescreen(homeListener)
}


/**
* home listener
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.dawnimpulse.wallup.ui.activities

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
Expand All @@ -15,6 +16,7 @@ import com.dawnimpulse.wallup.R
import com.dawnimpulse.wallup.utils.functions.F
import com.dawnimpulse.wallup.utils.functions.putAny
import com.dawnimpulse.wallup.utils.functions.remove
import com.dawnimpulse.wallup.utils.functions.toast
import com.dawnimpulse.wallup.utils.reusables.ANALYTICS
import com.dawnimpulse.wallup.utils.reusables.AUTO_WALLPAPER
import com.dawnimpulse.wallup.utils.reusables.CRASHLYTICS
Expand All @@ -31,6 +33,7 @@ class SettingsActivity : AppCompatActivity() {
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
setContentView(R.layout.activity_settings)
supportFragmentManager
.beginTransaction()
Expand All @@ -57,26 +60,26 @@ class SettingsActivity : AppCompatActivity() {
setPreferencesFromResource(R.xml.preferences, rootKey)

// get preferences
//wallStatus = findPreference("wallStatus")!!
//wallInterval = findPreference("wallInterval")!!
//wallWifi = findPreference("wallWifi")!!
wallStatus = findPreference("wallStatus")!!
wallInterval = findPreference("wallInterval")!!
wallWifi = findPreference("wallWifi")!!
crashlytics = findPreference("crashlytics")!!
analytics = findPreference("analytics")!!
cache = findPreference("cache")!!

// setting application version
findPreference<Preference>("version")!!.summary = "v${BuildConfig.VERSION_NAME}"
findPreference<Preference>("version")!!.summary = "v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"

// setting cache
cache.onPreferenceClickListener = this
cache.onPreferenceClickListener = this
setCache()

// setting time interval
/*
val time = Prefs.getString("wallInterval", "1440")!!.toLong()

// interval naming
val timing = when (time) {
15.toLong() -> "15 min"
30.toLong() -> "30 min"
60.toLong() -> "1 hour"
180.toLong() -> "3 hours"
Expand All @@ -90,7 +93,7 @@ class SettingsActivity : AppCompatActivity() {

wallStatus.onPreferenceChangeListener = this
wallInterval.onPreferenceChangeListener = this
wallWifi.onPreferenceChangeListener = this*/
wallWifi.onPreferenceChangeListener = this

}

Expand All @@ -110,7 +113,7 @@ class SettingsActivity : AppCompatActivity() {
} else {
// wallpaper disabled

WorkManager.getInstance().cancelWorkById(UUID.fromString(Prefs.getString(AUTO_WALLPAPER, "")))
WorkManager.getInstance(context!!).cancelWorkById(UUID.fromString(Prefs.getString(AUTO_WALLPAPER, "")))
Prefs.remove(AUTO_WALLPAPER)
FileUtils.deleteDirectory(context!!.filesDir)
}
Expand Down Expand Up @@ -140,7 +143,7 @@ class SettingsActivity : AppCompatActivity() {
* preference click
*/
override fun onPreferenceClick(preference: Preference?): Boolean {
when(preference){
when (preference) {
cache -> {
F.deleteCache(context!!)
cache.summary = "0 MB"
Expand All @@ -156,7 +159,7 @@ class SettingsActivity : AppCompatActivity() {

// remove wallpaper if exists
if (Prefs.contains(AUTO_WALLPAPER)) {
WorkManager.getInstance().cancelWorkById(UUID.fromString(Prefs.getString(AUTO_WALLPAPER, "")))
WorkManager.getInstance(context!!).cancelWorkById(UUID.fromString(Prefs.getString(AUTO_WALLPAPER, "")))
Prefs.remove(AUTO_WALLPAPER)
}

Expand All @@ -175,11 +178,12 @@ class SettingsActivity : AppCompatActivity() {
.setConstraints(builder)
.build()

WorkManager.getInstance().enqueue(uploadWorkRequest)
WorkManager.getInstance(context!!).enqueue(uploadWorkRequest)
Prefs.putAny(AUTO_WALLPAPER, uploadWorkRequest.id.toString())

// interval naming
val timing = when (time) {
15.toLong() -> "15 min"
30.toLong() -> "30 min"
60.toLong() -> "1 hour"
180.toLong() -> "3 hours"
Expand All @@ -190,13 +194,15 @@ class SettingsActivity : AppCompatActivity() {
else -> "7 days"
}
wallInterval.summary = "Change every $timing (tap to change)"

context!!.toast("please wait few minutes for wallpapers to cache on device")
}

/**
* set cache
*/
private fun setCache(){
F.appCache(context!!){
private fun setCache() {
F.appCache(context!!) {
cache.summary = "$it (tap to clean cache)"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
package com.dawnimpulse.wallup.ui.holders

import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.dawnimpulse.wallup.R
import com.dawnimpulse.wallup.ui.activities.SettingsActivity
import com.dawnimpulse.wallup.utils.functions.openActivity
import com.dawnimpulse.wallup.utils.functions.putAny
import com.dawnimpulse.wallup.utils.reusables.AUTO_WALLPAPER_FEATURE
import com.dawnimpulse.wallup.utils.reusables.Prefs
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.TapTargetView
import kotlinx.android.synthetic.main.inflator_home.view.*

/**
Expand All @@ -40,5 +47,31 @@ class HomeHolder(view: View) : RecyclerView.ViewHolder(view) {
info.setOnClickListener {
context.openActivity(SettingsActivity::class.java)
}

if (!Prefs.contains(AUTO_WALLPAPER_FEATURE)) {
TapTargetView.showFor(context as AppCompatActivity,
TapTarget.forView(info, "Auto Changing Wallpaper", "Tap to set Auto Changing Wallpaper and also view other settings & help options")
.outerCircleColor(R.color.colorAccent)
.targetCircleColor(R.color.black)
.titleTextColor(R.color.black)
.descriptionTextColor(R.color.black)
,
object: TapTargetView.Listener() {
override fun onOuterCircleClick(view: TapTargetView?) {
super.onOuterCircleClick(view)
Prefs.putAny(AUTO_WALLPAPER_FEATURE,true)
view!!.dismiss(true)
}

override fun onTargetClick(view: TapTargetView?) {
super.onTargetClick(view)
Prefs.putAny(AUTO_WALLPAPER_FEATURE,true)
view!!.dismiss(true)
}
}
)
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ErrorWallupUtil {
val error: ErrorWallupObject

try {
error = converter.convert(response.errorBody()!!)
error = converter.convert(response.errorBody()!!)!!
} catch (e: Exception) {
return ErrorWallupObject()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ object ImageHandler {
Glide.with(context)
.asBitmap()
.load("$url&fm=webp")
.diskCacheStrategy(DiskCacheStrategy.NONE)
.listener(object : RequestListener<Bitmap> {

override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const val WALLPAPER_WIFI = "wallpaperWifi"
const val CRASHLYTICS = "crashlytics"
const val ANALYTICS = "analytics"
const val RANDOM = "random"
const val AUTO_WALLPAPER_FEATURE = "autoWallpaperFeature"

const val FAIL_LOAD_MORE = "failLoadMore"
const val FAIL_LOAD_MORE_V = "failLoadMoreV"
Expand Down
40 changes: 21 additions & 19 deletions app/src/main/kotlin/com/dawnimpulse/wallup/workers/AutoWallpaper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import com.dawnimpulse.wallup.utils.handlers.StorageHandler
import com.google.common.util.concurrent.ListenableFuture
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.apache.commons.io.FileUtils
import org.apache.commons.io.comparator.LastModifiedFileComparator
import java.io.File
Expand Down Expand Up @@ -111,8 +113,6 @@ class AutoWallpaper(private val appContext: Context, workerParams: WorkerParamet
} else
// get wallpaper for file from dir
setWallpaper(callback)


}


Expand All @@ -127,24 +127,26 @@ class AutoWallpaper(private val appContext: Context, workerParams: WorkerParamet

// file found
if (file.exists()) {
val bitmap = BitmapFactory.decodeFile(file.path)
// check if bitmap is not null
if (bitmap != null) {
// set bitmap and increment lastWall
wallpaperManager.setBitmap(bitmap)
handler.post {
appContext.toast("wallpaper changed")
}
GlobalScope.launch {
val bitmap = BitmapFactory.decodeFile(file.path)
// check if bitmap is not null
if (bitmap != null) {
// set bitmap and increment lastWall
wallpaperManager.setBitmap(bitmap)
handler.post {
appContext.toast("wallpaper changed")
}

// delete the file
FileUtils.deleteQuietly(file)
callback(true)
// delete the file
FileUtils.deleteQuietly(file)
callback(true)

} else {
// bitmap is null
// delete the file
FileUtils.deleteQuietly(file)
callback(false)
} else {
// bitmap is null
// delete the file
FileUtils.deleteQuietly(file)
callback(false)
}
}
} else {
// file not found
Expand All @@ -157,7 +159,7 @@ class AutoWallpaper(private val appContext: Context, workerParams: WorkerParamet
// fetch images from server
// ----------------------------
private fun imagesFetching(callback: (Boolean) -> Unit) {
WallupRepo.getRandomTagImges("homescreen", 10) { e, r ->
WallupRepo.getRandomTagImges("homescreen", 5) { e, r ->
e?.let {
callback(false)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/vd_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="24"
android:viewportHeight="24" android:width="24dp" android:height="24dp">
<path android:fillColor="@color/black"
<path android:fillColor="@color/white"
android:pathData="M17 3H14V5H17V21H7V5H10V3H7A2 2 0 0 0 5 5V21A2 2 0 0 0 7 23H17A2 2 0 0 0 19 21V5A2 2 0 0 0 17 3M12 7A2 2 0 0 1 14 9A2 2 0 0 1 12 11A2 2 0 0 1 10 9A2 2 0 0 1 12 7M16 15H8V14C8 12.67 10.67 12 12 12C13.33 12 16 12.67 16 14V15M16 18H8V17H16V18M12 20H8V19H12V20M13 5H11V1H13V5Z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/vd_agent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:fillColor="@color/white"
android:pathData="M18.72,14.76C19.07,13.91 19.26,13 19.26,12C19.26,11.28 19.15,10.59 18.96,9.95C18.31,10.1 17.63,10.18 16.92,10.18C13.86,10.18 11.15,8.67 9.5,6.34C8.61,8.5 6.91,10.26 4.77,11.22C4.73,11.47 4.73,11.74 4.73,12A7.27,7.27 0,0 0,12 19.27C13.05,19.27 14.06,19.04 14.97,18.63C15.54,19.72 15.8,20.26 15.78,20.26C14.14,20.81 12.87,21.08 12,21.08C9.58,21.08 7.27,20.13 5.57,18.42C4.53,17.38 3.76,16.11 3.33,14.73H2V10.18H3.09C3.93,6.04 7.6,2.92 12,2.92C14.4,2.92 16.71,3.87 18.42,5.58C19.69,6.84 20.54,8.45 20.89,10.18H22V14.67H22V14.69L22,14.73H21.94L18.38,18L13.08,17.4V15.73H17.91L18.72,14.76M9.27,11.77C9.57,11.77 9.86,11.89 10.07,12.11C10.28,12.32 10.4,12.61 10.4,12.91C10.4,13.21 10.28,13.5 10.07,13.71C9.86,13.92 9.57,14.04 9.27,14.04C8.64,14.04 8.13,13.54 8.13,12.91C8.13,12.28 8.64,11.77 9.27,11.77M14.72,11.77C15.35,11.77 15.85,12.28 15.85,12.91C15.85,13.54 15.35,14.04 14.72,14.04C14.09,14.04 13.58,13.54 13.58,12.91A1.14,1.14 0,0 1,14.72 11.77Z"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/vd_github.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="24"
android:viewportHeight="24" android:width="24dp" android:height="24dp">
<path android:fillColor="@color/black"
<path android:fillColor="@color/white"
android:pathData="M12 2A10 10 0 0 0 2 12C2 16.42 4.87 20.17 8.84 21.5C9.34 21.58 9.5 21.27 9.5 21C9.5 20.77 9.5 20.14 9.5 19.31C6.73 19.91 6.14 17.97 6.14 17.97C5.68 16.81 5.03 16.5 5.03 16.5C4.12 15.88 5.1 15.9 5.1 15.9C6.1 15.97 6.63 16.93 6.63 16.93C7.5 18.45 8.97 18 9.54 17.76C9.63 17.11 9.89 16.67 10.17 16.42C7.95 16.17 5.62 15.31 5.62 11.5C5.62 10.39 6 9.5 6.65 8.79C6.55 8.54 6.2 7.5 6.75 6.15C6.75 6.15 7.59 5.88 9.5 7.17C10.29 6.95 11.15 6.84 12 6.84C12.85 6.84 13.71 6.95 14.5 7.17C16.41 5.88 17.25 6.15 17.25 6.15C17.8 7.5 17.45 8.54 17.35 8.79C18 9.5 18.38 10.39 18.38 11.5C18.38 15.32 16.04 16.16 13.81 16.41C14.17 16.72 14.5 17.33 14.5 18.26C14.5 19.6 14.5 20.68 14.5 21C14.5 21.27 14.66 21.59 15.17 21.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2Z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/vd_image_off.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="24"
android:viewportHeight="24" android:width="24dp" android:height="24dp">
<path android:fillColor="@color/black"
<path android:fillColor="@color/white"
android:pathData="M2.28 3L1 4.27L3 6.27V19A2 2 0 0 0 5 21H17.73L19.73 23L21 21.72L2.28 3M4.83 3L21 19.17V5C21 3.89 20.1 3 19 3H4.83M8.5 13.5L11 16.5L12 15.25L14.73 18H5L8.5 13.5Z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/vd_lib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:fillColor="@color/white"
android:pathData="M4,3C2.89,3 2,3.89 2,5V15A2,2 0,0 0,4 17H12V22L15,19L18,22V17H20A2,2 0,0 0,22 15V8L22,6V5A2,2 0,0 0,20 3H16V3H4M12,5L15,7L18,5V8.5L21,10L18,11.5V15L15,13L12,15V11.5L9,10L12,8.5V5M4,5H9V7H4V5M4,9H7V11H4V9M4,13H9V15H4V13Z"/>
</vector>
Loading

0 comments on commit 8671758

Please sign in to comment.