From 1fe72b3a9d426a017920cc4e7d0b01d226a81f95 Mon Sep 17 00:00:00 2001 From: DawnImpulse Date: Sat, 22 Sep 2018 16:06:39 +0530 Subject: [PATCH] Improvement: Tag clicks & other bug fixes (trello.com/c/bcjff5Oc) --- app/build.gradle | 8 +- .../wallup/activities/ChangesActivity.kt | 27 +++++- .../activities/GeneralImagesActivity.kt | 13 +++ .../wallup/activities/ImageActivity.kt | 17 ++-- .../wallup/adapters/TagsAdapter.kt | 14 ++- .../wallup/models/UnsplashModel.kt | 17 ++++ .../wallup/repositories/UnsplashRepository.kt | 25 +++++ .../wallup/sheets/ModalSheetNav.kt | 2 +- .../wallup/source/RetroUnsplashSource.kt | 8 ++ .../kotlin/com/dawnimpulse/wallup/utils/C.kt | 3 + .../kotlin/com/dawnimpulse/wallup/utils/F.kt | 6 +- .../kotlin/com/dawnimpulse/wallup/utils/ML.kt | 10 +- .../dawnimpulse/wallup/utils/RemoteConfig.kt | 7 +- .../com/dawnimpulse/wallup/utils/Ripple.kt | 35 ------- app/src/main/res/layout/activity_changes.xml | 91 ++++++++++++++++++- app/src/main/res/values/strings.xml | 5 + build.gradle | 4 +- 17 files changed, 218 insertions(+), 74 deletions(-) delete mode 100644 app/src/main/kotlin/com/dawnimpulse/wallup/utils/Ripple.kt diff --git a/app/build.gradle b/app/build.gradle index 1908e09..6abb3cb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,6 +13,9 @@ android { versionName version_name testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true + ndk { + abiFilters "armeabi-v7a", "x86" + } } buildTypes { release { @@ -48,8 +51,8 @@ dependencies { implementation 'com.google.firebase:firebase-config:16.0.0' implementation 'com.google.firebase:firebase-database:16.0.2' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' - implementation 'com.google.firebase:firebase-ml-vision:17.0.0' - implementation 'com.google.firebase:firebase-ml-vision-image-label-model:15.0.0' + /*implementation 'com.google.firebase:firebase-ml-vision:17.0.0' + implementation 'com.google.firebase:firebase-ml-vision-image-label-model:15.0.0'*/ //--------------- 3rd Party Libraries ------------------- implementation 'com.github.bumptech.glide:glide:3.7.0' //image loading @@ -63,7 +66,6 @@ dependencies { implementation 'com.dawnimpulse:permissions:0.1.1' //permission manager implementation 'com.pixplicity.easyprefs:library:1.9.0' //preferences manager implementation 'me.grantland:autofittextview:0.2.1' //text auto-fit - implementation 'com.balysv:material-ripple:1.0.2'//material ripple implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0' //kotlin co-routines //------------------ Additional ------------------------- diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ChangesActivity.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ChangesActivity.kt index ff02762..411df62 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ChangesActivity.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ChangesActivity.kt @@ -14,11 +14,15 @@ OR PERFORMANCE OF THIS SOFTWARE.*/ package com.dawnimpulse.wallup.activities import android.content.Intent +import android.net.Uri import android.os.Bundle import android.support.v7.app.AppCompatActivity +import android.view.View +import androidx.core.widget.toast import com.dawnimpulse.wallup.BuildConfig import com.dawnimpulse.wallup.R import com.dawnimpulse.wallup.utils.C +import com.dawnimpulse.wallup.utils.RemoteConfig import com.pixplicity.easyprefs.library.Prefs import kotlinx.android.synthetic.main.activity_changes.* @@ -31,20 +35,33 @@ import kotlinx.android.synthetic.main.activity_changes.* * * @note Updates : */ -class ChangesActivity : AppCompatActivity() { +class ChangesActivity : AppCompatActivity(), View.OnClickListener { + // on create override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_changes) next() - changesFab.setOnClickListener { - startActivity(Intent(this, MainActivity::class.java)) - finish() + changesFab.setOnClickListener(this) + changesPrivacy.setOnClickListener(this) + } + + // on click + override fun onClick(v: View) { + when (v.id) { + changesFab.id -> { + startActivity(Intent(this, MainActivity::class.java)) + finish() + } + changesPrivacy.id -> { + toast("opening in browser") + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(RemoteConfig.getPrivacyLink()))) + } } } - private fun next(){ + private fun next() { if (Prefs.contains(C.VERSION_CODE)) { if (Prefs.getInt(C.VERSION_CODE, 0) == BuildConfig.VERSION_CODE) { startActivity(Intent(this, MainActivity::class.java)) diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/activities/GeneralImagesActivity.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/activities/GeneralImagesActivity.kt index df40d38..cc097ae 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/activities/GeneralImagesActivity.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/activities/GeneralImagesActivity.kt @@ -24,6 +24,7 @@ import kotlinx.android.synthetic.main.activity_general_images.* * * @note Updates : * Saksham - 2018 09 09 - master - collection images + * Saksham - 2018 09 22 - master - random images tag */ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener, SwipeRefreshLayout.OnRefreshListener, OnLoadMoreListener { @@ -38,6 +39,7 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener, private lateinit var images: MutableList private lateinit var colId: String private lateinit var colType: String + private lateinit var tag: String // on create override fun onCreate(savedInstanceState: Bundle?) { @@ -58,6 +60,11 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener, colType = intent.extras.getString(C.COLLECTION) paginatedImages() } + C.TAG -> { + current = 3 + tag = intent.extras.getString(C.TAG) + randomImages() + } } generalImagesFab.setOnClickListener(this) @@ -77,6 +84,7 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener, 0 -> randomImages() 1 -> paginatedImages() 2 -> paginatedImages() + 3 -> randomImages() } } @@ -128,6 +136,11 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener, else model.randomImages(callback) } + 3 -> { + model.randomImagesTag(tag) { e, r -> + setRandomImages(e, r) + } + } } } diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ImageActivity.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ImageActivity.kt index 241f8d2..12b452b 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/activities/ImageActivity.kt @@ -21,19 +21,20 @@ import android.net.Uri import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.support.v7.graphics.Palette -import android.support.v7.widget.LinearLayoutManager import android.view.View import androidx.core.os.bundleOf import androidx.core.widget.toast import com.dawnimpulse.permissions.android.Permissions import com.dawnimpulse.wallup.R -import com.dawnimpulse.wallup.adapters.TagsAdapter +import com.dawnimpulse.wallup.R.id.* import com.dawnimpulse.wallup.handlers.* import com.dawnimpulse.wallup.models.UnsplashModel import com.dawnimpulse.wallup.pojo.ImagePojo import com.dawnimpulse.wallup.sheets.ModalSheetExif -import com.dawnimpulse.wallup.utils.* -import com.google.firebase.ml.vision.label.FirebaseVisionLabel +import com.dawnimpulse.wallup.utils.C +import com.dawnimpulse.wallup.utils.Config +import com.dawnimpulse.wallup.utils.F +import com.dawnimpulse.wallup.utils.Toast import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_image.* @@ -205,9 +206,9 @@ class ImageActivity : AppCompatActivity(), View.OnClickListener { color() movingImage.setImageBitmap(it) imagePreviewProgress.visibility = View.GONE - ML.labels(it) { + /*ML.labels(it) { setTags(it) - } + }*/ } //F.underline(imagePreviewStatistics) @@ -236,12 +237,12 @@ class ImageActivity : AppCompatActivity(), View.OnClickListener { //imagePreviewWallpaperT.setTextColor(color) } - // set tags + /* // set tags private fun setTags(tags: List) { imagePreviewTags.visibility = View.VISIBLE val sortedTags = F.sortLabels(tags) imagePreviewTags.clipToPadding = false imagePreviewTags.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false) imagePreviewTags.adapter = TagsAdapter(lifecycle, sortedTags) - } + }*/ } diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/adapters/TagsAdapter.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/adapters/TagsAdapter.kt index d0e28a3..49c97f7 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/adapters/TagsAdapter.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/adapters/TagsAdapter.kt @@ -20,9 +20,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import com.dawnimpulse.wallup.R import com.dawnimpulse.wallup.handlers.ImageHandler -import com.dawnimpulse.wallup.utils.C import com.dawnimpulse.wallup.viewholders.TagsHolder -import com.google.firebase.ml.vision.label.FirebaseVisionLabel /** * @author Saksham @@ -32,7 +30,7 @@ import com.google.firebase.ml.vision.label.FirebaseVisionLabel * * @note Updates : */ -class TagsAdapter(private val lifecycle: Lifecycle, private val tags: List) +class TagsAdapter(private val lifecycle: Lifecycle, private val tags: List) : RecyclerView.Adapter() { private lateinit var context: Context @@ -50,7 +48,13 @@ class TagsAdapter(private val lifecycle: Lifecycle, private val tags: List Unit) { + UnsplashRepository.randomImagesTag(keyword){ e,r -> + lifecycle.addObserver(object : LifecycleObserver { + var once = true + @OnLifecycleEvent(Lifecycle.Event.ON_START) + fun onResume() { + if (once) { + callback(e, r) + once = false + } + } + }) + } + } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/repositories/UnsplashRepository.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/repositories/UnsplashRepository.kt index 5698ea2..df74119 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/repositories/UnsplashRepository.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/repositories/UnsplashRepository.kt @@ -39,6 +39,7 @@ import retrofit2.Response * 2018 09 02 - master - Saksham - random user images * 2018 09 08 - master - Saksham - featured collections * 2018 09 14 - master - Saksham - user's collections + * 2018 09 22 - master - Saksham - random images tag */ object UnsplashRepository { private val NAME = "UnsplashRepository" @@ -397,4 +398,28 @@ object UnsplashRepository { }) } + // random images with a tag + fun randomImagesTag(keyword: String, callback: (Any?, Any?) -> Unit) { + val apiClient = RetroApiClient.getClient()!!.create(RetroUnsplashSource::class.java) + val call = apiClient.randomImagesTag( + Config.UNSPLASH_API_KEY, + keyword + ) + + call.enqueue(object : Callback> { + + override fun onResponse(call: Call>?, response: Response>) { + if (response.isSuccessful) { + callback(null, response.body()) + } else { + callback(Gson().toJson(response.errorBody()).toString(), null) + } + } + + override fun onFailure(call: Call>?, t: Throwable?) { + callback(t.toString(), null) + } + }) + } + } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/sheets/ModalSheetNav.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/sheets/ModalSheetNav.kt index 5161ff2..6da1634 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/sheets/ModalSheetNav.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/sheets/ModalSheetNav.kt @@ -85,7 +85,7 @@ class ModalSheetNav : RoundedBottomSheetDialogFragment(), View.OnClickListener { dismiss() } sheetNavUpdateL.id -> { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.dawnimpulse.wallup"))) + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.dawnimpulse.wallup"))) } } } diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/source/RetroUnsplashSource.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/source/RetroUnsplashSource.kt index 0297bf3..06cea41 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/source/RetroUnsplashSource.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/source/RetroUnsplashSource.kt @@ -34,6 +34,7 @@ OR PERFORMANCE OF THIS SOFTWARE.*/ * Saksham - 2018 09 02 - recent - random user images * Saksham - 2018 09 08 - recent - featured collections * Saksham - 2018 09 14 - recent - users's collections + * Saksham - 2018 09 22 - recent - random photos with a tag */ interface RetroUnsplashSource { @@ -161,4 +162,11 @@ interface RetroUnsplashSource { @Query(C.PER_PAGE) count: Int ): Call> + // random photos with a tag + @GET("/photos/random?count=30") + fun randomImagesTag( + @Header(C.AUTHORIZATION) authorization: String, + @Query(C.QUERY) query: String + ): Call> + } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/C.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/C.kt index ec0e4a9..25bd69c 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/C.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/C.kt @@ -51,6 +51,9 @@ object C { const val UPDATE = "update" const val UPDATE_PRODUCTION = "update_production" const val DAWN_IMPULSE = "dawnimpulse" + const val QUERY = "query" + const val TAG = "tag" + const val PRIVACY = "privacy" const val UTM = "?utm_source=wallup&utm_medium=referral" const val WALLUP_PLAY = "https://play.google.com/store/apps/details?id=com.dawnimpulse.wallup" diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/F.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/F.kt index 918def4..2c831cb 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/F.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/F.kt @@ -5,9 +5,7 @@ import android.os.Build import android.text.Html import android.text.Spanned import android.widget.TextView -import com.google.firebase.ml.vision.label.FirebaseVisionLabel import java.text.SimpleDateFormat -import java.util.* /* @@ -106,10 +104,10 @@ object F { } // sort labels - fun sortLabels(labels: List): List { + /*fun sortLabels(labels: List): List { Collections.sort(labels) { o1, o2 -> o2.confidence.compareTo(o1.confidence) } return labels - } + }*/ } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/ML.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/ML.kt index dc96aa5..bbc09a7 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/ML.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/ML.kt @@ -12,12 +12,6 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.*/package com.dawnimpulse.wallup.utils -import android.graphics.Bitmap -import com.google.firebase.ml.vision.FirebaseVision -import com.google.firebase.ml.vision.common.FirebaseVisionImage -import com.google.firebase.ml.vision.label.FirebaseVisionLabel -import com.google.firebase.ml.vision.label.FirebaseVisionLabelDetectorOptions - /** * @author Saksham @@ -31,7 +25,7 @@ object ML { private val NAME = "ML" // predicting image labels - fun labels(bitmap: Bitmap, callback: (List) -> Unit) { + /*fun labels(bitmap: Bitmap, callback: (List) -> Unit) { val options = FirebaseVisionLabelDetectorOptions.Builder() .setConfidenceThreshold(0.6f) .build() @@ -51,5 +45,5 @@ object ML { L.e(NAME, it.message!!) } - } + }*/ } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/RemoteConfig.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/RemoteConfig.kt index d8b2abf..af2cdb9 100644 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/RemoteConfig.kt +++ b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/RemoteConfig.kt @@ -55,7 +55,7 @@ object RemoteConfig { } - // get remote config values + // get remote config update value fun getProductionUpdateValues(): UpdatePojo? { val value = FirebaseRemoteConfig.getInstance().getString(C.UPDATE_PRODUCTION) value?.let{ @@ -64,4 +64,9 @@ object RemoteConfig { return null; } + // get remote config values + fun getPrivacyLink(): String { + return FirebaseRemoteConfig.getInstance().getString(C.PRIVACY) + } + } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/Ripple.kt b/app/src/main/kotlin/com/dawnimpulse/wallup/utils/Ripple.kt deleted file mode 100644 index 170c2d4..0000000 --- a/app/src/main/kotlin/com/dawnimpulse/wallup/utils/Ripple.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* -ISC License - -Copyright 2018, Saksham (DawnImpulse) - -Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, -provided that the above copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -OR PERFORMANCE OF THIS SOFTWARE.*/package com.dawnimpulse.wallup.utils - -import android.view.View -import com.balysv.materialripple.MaterialRippleLayout - -/** - * @author Saksham - * - * @note Last Branch Update - - * @note Created on 2018-09-20 by Saksham - * - * @note Updates : - */ -object Ripple { - - // add ripple animation to view - fun add(color: Int, view: View) { - MaterialRippleLayout.on(view) - .rippleColor(color) - .rippleOverlay(true) - .create(); - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_changes.xml b/app/src/main/res/layout/activity_changes.xml index bc1c045..976c0d9 100644 --- a/app/src/main/res/layout/activity_changes.xml +++ b/app/src/main/res/layout/activity_changes.xml @@ -33,7 +33,7 @@ android:orientation="vertical"> - + --> + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + Dashboard Notifications + NOTE: This app is Open Source hence completely free to use with no Ads at all. Kindly go through our Privacy Policy . NOTE: Trending Images are updated here everyday around 5.30 AM GMT New: Photographer\'s collections in their profile. New: Open unsplash photo links directly in Wallup. @@ -27,4 +28,8 @@ OR PERFORMANCE OF THIS SOFTWARE. New: Shared images will be now saved in Downloads/Wallup/ . Bug Fixed: Image sharing crash on device running Android 7 & above. Improvements: Many other bugs fixes & performance improvements. + + New: Using machine learning to predict tags for a image (can sometimes give irrelevant results). + New: Using ripple animations for click throughout app. + Improvements: Many other bugs fixes & performance improvements. diff --git a/build.gradle b/build.gradle index babb6f3..d3da038 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,8 @@ buildscript { ext.kotlin_version = '1.2.30' - ext.version_code = 4 - ext.version_name = "0.4.0" + ext.version_code = 5 + ext.version_name = "0.5.0" repositories { google() jcenter()