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

Commit

Permalink
Improvement: Tag clicks & other bug fixes (trello.com/c/bcjff5Oc)
Browse files Browse the repository at this point in the history
  • Loading branch information
DawnImpulse committed Sep 22, 2018
1 parent 7e2f50f commit 1fe72b3
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 74 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ android {
versionName version_name
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
buildTypes {
release {
Expand Down Expand Up @@ -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
Expand All @@ -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 -------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -38,6 +39,7 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
private lateinit var images: MutableList<ImagePojo?>
private lateinit var colId: String
private lateinit var colType: String
private lateinit var tag: String

// on create
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -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)
Expand All @@ -77,6 +84,7 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
0 -> randomImages()
1 -> paginatedImages()
2 -> paginatedImages()
3 -> randomImages()
}
}

Expand Down Expand Up @@ -128,6 +136,11 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
else
model.randomImages(callback)
}
3 -> {
model.randomImagesTag(tag) { e, r ->
setRandomImages(e, r)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -236,12 +237,12 @@ class ImageActivity : AppCompatActivity(), View.OnClickListener {
//imagePreviewWallpaperT.setTextColor(color)
}

// set tags
/* // set tags
private fun setTags(tags: List<FirebaseVisionLabel>) {
imagePreviewTags.visibility = View.VISIBLE
val sortedTags = F.sortLabels(tags)
imagePreviewTags.clipToPadding = false
imagePreviewTags.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
imagePreviewTags.adapter = TagsAdapter(lifecycle, sortedTags)
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +30,7 @@ import com.google.firebase.ml.vision.label.FirebaseVisionLabel
*
* @note Updates :
*/
class TagsAdapter(private val lifecycle: Lifecycle, private val tags: List<FirebaseVisionLabel?>)
class TagsAdapter(private val lifecycle: Lifecycle, private val tags: List<ImageHandler?>)
: RecyclerView.Adapter<TagsHolder>() {

private lateinit var context: Context
Expand All @@ -50,7 +48,13 @@ class TagsAdapter(private val lifecycle: Lifecycle, private val tags: List<Fireb

// binding view holder
override fun onBindViewHolder(holder: TagsHolder, position: Int) {
holder.label.text = tags[position]!!.label
ImageHandler.setImageInView(lifecycle,holder.image,"${C.TAGS_SOURCE}${tags[position]!!.label}")
/*holder.label.text = tags[position]!!.label
ImageHandler.setImageInView(lifecycle, holder.image, "${C.TAGS_SOURCE}${tags[position]!!.label}")
holder.image.setOnClickListener {
var intent = Intent(context, GeneralImagesActivity::class.java)
intent.putExtra(C.TYPE, C.TAG)
intent.putExtra(C.TAG, tags[position]!!.label)
context.startActivity(intent)
}*/
}
}
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/dawnimpulse/wallup/models/UnsplashModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.dawnimpulse.wallup.repositories.UnsplashRepository
* 2018 09 01 - master - Saksham - image details
* 2018 09 02 - master - Saksham - random user images
* 2018 09 08 - master - Saksham - featured curatedCollections
* 2018 09 22 - master - Saksham - random images tag
*/
class UnsplashModel() {
lateinit var lifecycle: Lifecycle
Expand Down Expand Up @@ -220,4 +221,20 @@ class UnsplashModel() {
})
}
}

// random images with a keyword
fun randomImagesTag(keyword: String, callback: (Any?, Any?) -> 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
}
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<List<ImagePojo>> {

override fun onResponse(call: Call<List<ImagePojo>>?, response: Response<List<ImagePojo>>) {
if (response.isSuccessful) {
callback(null, response.body())
} else {
callback(Gson().toJson(response.errorBody()).toString(), null)
}
}

override fun onFailure(call: Call<List<ImagePojo>>?, t: Throwable?) {
callback(t.toString(), null)
}
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -161,4 +162,11 @@ interface RetroUnsplashSource {
@Query(C.PER_PAGE) count: Int
): Call<List<CollectionPojo>>

// random photos with a tag
@GET("/photos/random?count=30")
fun randomImagesTag(
@Header(C.AUTHORIZATION) authorization: String,
@Query(C.QUERY) query: String
): Call<List<ImagePojo>>

}
3 changes: 3 additions & 0 deletions app/src/main/kotlin/com/dawnimpulse/wallup/utils/C.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/kotlin/com/dawnimpulse/wallup/utils/F.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*


/*
Expand Down Expand Up @@ -106,10 +104,10 @@ object F {
}

// sort labels
fun sortLabels(labels: List<FirebaseVisionLabel>): List<FirebaseVisionLabel> {
/*fun sortLabels(labels: List<FirebaseVisionLabel>): List<FirebaseVisionLabel> {
Collections.sort(labels) { o1, o2 ->
o2.confidence.compareTo(o1.confidence)
}
return labels
}
}*/
}
10 changes: 2 additions & 8 deletions app/src/main/kotlin/com/dawnimpulse/wallup/utils/ML.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +25,7 @@ object ML {
private val NAME = "ML"

// predicting image labels
fun labels(bitmap: Bitmap, callback: (List<FirebaseVisionLabel>) -> Unit) {
/*fun labels(bitmap: Bitmap, callback: (List<FirebaseVisionLabel>) -> Unit) {
val options = FirebaseVisionLabelDetectorOptions.Builder()
.setConfidenceThreshold(0.6f)
.build()
Expand All @@ -51,5 +45,5 @@ object ML {
L.e(NAME, it.message!!)
}
}
}*/
}
Loading

0 comments on commit 1fe72b3

Please sign in to comment.