Skip to content

Commit

Permalink
Merge pull request #101 from druger/dev
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
druger authored Jan 19, 2020
2 parents fbe6046 + daa5058 commit 0f622c2
Show file tree
Hide file tree
Showing 88 changed files with 1,607 additions and 1,442 deletions.
28 changes: 13 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.firebase-perf'

Expand All @@ -22,14 +21,14 @@ android {
}
}
compileSdkVersion 29
buildToolsVersion '29.0.0'
buildToolsVersion '29.0.2'

defaultConfig {
applicationId "com.druger.aboutwork"
minSdkVersion 21
targetSdkVersion 29
versionCode 4
versionName "1.0.3"
versionCode 5
versionName "1.1"
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true

Expand Down Expand Up @@ -85,35 +84,34 @@ repositories {
}

dependencies {
def appCenterSdkVersion = '2.4.1'
def appCenterSdkVersion = '2.5.1'

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha02'
implementation 'com.google.android.material:material:1.2.0-alpha02' // не обновлять пока не будет нормально отображаться FAB
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.firebaseui:firebase-ui-auth:6.1.0'
implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.61'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.squareup.retrofit2:retrofit:2.7.0'
implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.8.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
implementation "com.github.moxy-community:moxy:2.0.2"
implementation "com.github.moxy-community:moxy-androidx:2.0.2"
kapt "com.github.moxy-community:moxy-compiler:2.0.2"
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.google.dagger:dagger:2.11'
implementation 'com.google.dagger:dagger:2.24'
testImplementation 'junit:junit:4.12'
kapt 'com.google.dagger:dagger-compiler:2.11'
kapt 'com.google.dagger:dagger-compiler:2.24'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.2'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2'
implementation 'com.thefinestartist:finestwebview:1.2.7'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'io.realm:android-adapters:3.1.0'
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.2'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.10.0'
Expand All @@ -123,7 +121,7 @@ dependencies {
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
implementation 'com.google.firebase:firebase-perf:19.0.2'
implementation 'com.google.firebase:firebase-perf:19.0.4'
}


Expand Down
19 changes: 3 additions & 16 deletions app/src/main/java/com/druger/aboutwork/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.druger.aboutwork

import android.app.Application
import android.content.Context
import com.druger.aboutwork.db.RealmHelper.Companion.REALM_NAME
import com.druger.aboutwork.db.RealmHelper.Companion.SCHEMA_VERSION
import com.druger.aboutwork.di.components.AppComponent
import com.druger.aboutwork.di.components.DaggerAppComponent
import com.druger.aboutwork.di.modules.AppModule
Expand All @@ -15,8 +13,6 @@ import com.microsoft.appcenter.analytics.Analytics
import com.microsoft.appcenter.crashes.Crashes
import com.squareup.leakcanary.LeakCanary
import com.squareup.leakcanary.RefWatcher
import io.realm.Realm
import io.realm.RealmConfiguration
import timber.log.Timber


Expand All @@ -40,11 +36,12 @@ class App : Application() {
super.onCreate()
// setupLeakCanary()
FirebaseApp.initializeApp(this)
setupRealm()
setupDagger2()
AndroidThreeTen.init(this)
setupTimber()
setupAppCenter()
if (!BuildConfig.DEBUG) {
setupAppCenter()
}
}

private fun setupAppCenter() {
Expand Down Expand Up @@ -73,14 +70,4 @@ class App : Application() {
refWatcher = LeakCanary.install(this)
}
}

private fun setupRealm() {
Realm.init(this)
val config = RealmConfiguration.Builder()
.schemaVersion(SCHEMA_VERSION)
.name(REALM_NAME)
.deleteRealmIfMigrationNeeded()
.build()
Realm.setDefaultConfiguration(config)
}
}
5 changes: 2 additions & 3 deletions app/src/main/java/com/druger/aboutwork/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ object Const {

object Bundles {

const val DEBOUNCE_SEARCH = 300
const val DEBOUNCE_SEARCH = 500

const val EDIT_MODE = "editMode"
const val NAME = "name"
const val USER_ID = "userId"
const val EMAIL = "email"
}

object Colors {
const val PURPLE_500 = "#47379F"
const val PURPLE_100 = "#D1C4E9"
const val GRAY_500 = "#9E9E9E"
const val BLACK = "#ff000000"
const val LIKE = "#3F2B96"
const val DISLIKE = "#EB5757"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LoginActivity : AppCompatActivity() {
.createSignInIntentBuilder()
.setAvailableProviders(listOf(
AuthUI.IdpConfig.PhoneBuilder().build(),
AuthUI.IdpConfig.EmailBuilder().build()
AuthUI.IdpConfig.GoogleBuilder().build()
))
.setLogo(R.drawable.ic_logo)
.setIsSmartLockEnabled(!BuildConfig.DEBUG, false)
Expand Down Expand Up @@ -98,14 +98,9 @@ class LoginActivity : AppCompatActivity() {
private fun saveNewUser() {
val firebaseUser = FirebaseAuth.getInstance().currentUser
val id = firebaseUser?.uid
val nameEmail = firebaseUser?.displayName
var namePhone = ""
if (nameEmail == null) {
namePhone = "User_" + id?.substring(0, 4)
firebaseUser?.let { setDisplayName(it, namePhone) }
}
val name = nameEmail ?: namePhone
val name = "User_" + id?.substring(0, 4)
val user = id?.let { User(it, name) }
firebaseUser?.let { setDisplayName(it, name) }
user?.let { FirebaseHelper.addUser(it, id) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class MainActivity : MvpAppCompatActivity(), MainView, BottomNavigationView.OnNa

override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_companies -> showCompanies()
R.id.action_search -> showCompanies()
R.id.action_my_reviews -> mainPresenter.onClickMyReviews()
R.id.action_setting -> showAccount()
}
Expand Down
122 changes: 66 additions & 56 deletions app/src/main/java/com/druger/aboutwork/adapters/CommentAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.collection.ArrayMap
import androidx.recyclerview.widget.RecyclerView
import com.druger.aboutwork.Const.Colors.BLACK
import com.druger.aboutwork.Const.Colors.DISLIKE
import com.druger.aboutwork.Const.Colors.GRAY_500
import com.druger.aboutwork.Const.Colors.LIKE
import com.druger.aboutwork.R
import com.druger.aboutwork.db.FirebaseHelper
Expand All @@ -23,6 +24,7 @@ import com.google.firebase.auth.FirebaseUser
class CommentAdapter(private val user: FirebaseUser?) : BaseRecyclerViewAdapter<Comment, CommentAdapter.CommentVH>() {

private var nameClickListener: OnNameClickListener? = null
private var likesDislikes: MutableMap<String, Boolean>? = null

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommentVH {
val itemView = inflate(R.layout.item_comment, parent)
Expand All @@ -42,75 +44,83 @@ class CommentAdapter(private val user: FirebaseUser?) : BaseRecyclerViewAdapter<
holder.ivDislike.setOnClickListener { dislikeClick(holder, comment) }
holder.tvUserName.setOnClickListener { nameClickListener?.onClick(comment) }

setColorLike(comment, holder)
setColorDislike(comment, holder)
setColorLikeDislike(comment, holder)
}

private fun setColorDislike(comment: Comment, holder: CommentVH) {
if (comment.myDislike) {
holder.ivDislike.setColorFilter(Color.parseColor(DISLIKE))
} else {
holder.ivDislike.setImageResource(R.drawable.thumb_down)
private fun setColorLikeDislike(comment: Comment, holder: CommentVH) {
holder.ivLike.setColorFilter(Color.parseColor(BLACK))
holder.ivDislike.setColorFilter(Color.parseColor(BLACK))
likesDislikes = comment.likesDislikes
likesDislikes?.let { likes ->
likes[user?.uid]?.let { myLike ->
if (myLike) {
holder.ivLike.setColorFilter(Color.parseColor(LIKE))
} else {
holder.ivDislike.setColorFilter(Color.parseColor(DISLIKE))
}
}
}
}

private fun dislikeClick(holder: CommentVH, comment: Comment) {
if (user != null) {
var dislike = comment.dislike
var like = comment.like
if (comment.myDislike) {
comment.dislike = --dislike
comment.myDislike = false
holder.ivDislike.setColorFilter(Color.parseColor(GRAY_500))
} else {
comment.dislike = ++dislike
comment.myDislike = true
holder.ivDislike.setColorFilter(Color.parseColor(DISLIKE))

if (comment.myLike) {
holder.ivLike.setColorFilter(Color.parseColor(GRAY_500))
comment.like = --like
comment.myLike = false
FirebaseHelper.likeComment(comment)
user?.let {
if (likesDislikes == null) likesDislikes = ArrayMap<String, Boolean>()
var likes = comment.like
var dislikes = comment.dislike
val userId = user.uid
val myLikeDislike = likesDislikes?.get(userId)

myLikeDislike?.let { likeDislike ->
if (!likeDislike) {
comment.dislike = --dislikes
holder.tvCountDislikes.text = dislikes.toString()
likesDislikes?.remove(userId)
} else {
comment.like = --likes
holder.tvCountLikes.text = likes.toString()

comment.dislike = ++dislikes
holder.tvCountDislikes.text = dislikes.toString()
userId.let { likesDislikes?.put(it, false) }
}
} ?: run {
comment.dislike = ++dislikes
holder.tvCountDislikes.text = dislikes.toString()
userId.let { likesDislikes?.put(it, false) }
}
FirebaseHelper.dislikeComment(comment)
} else {
Utils.showAuthDialog(holder.ivDislike.context, R.string.dislike_login, comment.reviewId)
}
}

private fun setColorLike(comment: Comment, holder: CommentVH) {
if (comment.myLike) {
holder.ivLike.setColorFilter(Color.parseColor(LIKE))
} else {
holder.ivLike.setImageResource(R.drawable.thumb_up)
comment.likesDislikes = this.likesDislikes
FirebaseHelper.likeOrDislikeComment(comment)
}
}

private fun likeClick(holder: CommentVH, comment: Comment) {
if (user != null) {
var like = comment.like
var dislike = comment.dislike
if (comment.myLike) {
comment.like = --like
comment.myLike = false
holder.ivLike.setColorFilter(Color.parseColor(GRAY_500))
} else {
comment.like = ++like
comment.myLike = true
holder.ivLike.setColorFilter(Color.parseColor(LIKE))

if (comment.myDislike) {
holder.ivDislike.setColorFilter(Color.parseColor(GRAY_500))
comment.dislike = --dislike
comment.myDislike = false
FirebaseHelper.dislikeComment(comment)
user?.let {
if (likesDislikes == null) likesDislikes = ArrayMap<String, Boolean>()
var likes = comment.like
var dislikes = comment.dislike
val userId = user.uid
val myLikeDislike = likesDislikes?.get(userId)
myLikeDislike?.let { likeDislike ->
if (likeDislike) {
comment.like = --likes
holder.tvCountLikes.text = likes.toString()
likesDislikes?.remove(userId)
} else {
comment.dislike = --dislikes
holder.tvCountDislikes.text = dislikes.toString()

comment.like = ++likes
holder.tvCountLikes.text = likes.toString()
userId.let { likesDislikes?.put(it, true) }
}

} ?: run {
comment.like = ++likes
holder.tvCountLikes.text = likes.toString()
userId.let { likesDislikes?.put(it, true) }
}
FirebaseHelper.likeComment(comment)
} else {
Utils.showAuthDialog(holder.ivLike.context, R.string.like_login, comment.reviewId)
comment.likesDislikes = this.likesDislikes
FirebaseHelper.likeOrDislikeComment(comment)
}
}

Expand Down
21 changes: 17 additions & 4 deletions app/src/main/java/com/druger/aboutwork/adapters/CompanyAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import com.druger.aboutwork.model.Company

class CompanyAdapter : BaseRecyclerViewAdapter<Company, RecyclerView.ViewHolder>() {

private var isLoading = false

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
var view = inflate(R.layout.item_company, parent)
val viewHolder = CompanyVH(view)
Expand Down Expand Up @@ -58,7 +60,7 @@ class CompanyAdapter : BaseRecyclerViewAdapter<Company, RecyclerView.ViewHolder>
}

override fun getItemViewType(position: Int): Int {
return if (getItem(position) == null) TYPE_LOADING else TYPE_COMPANY
return if (isLoading && position == itemCount - 1) TYPE_LOADING else TYPE_COMPANY
}

private class CompanyVH(itemView: View) : BaseViewHolder(itemView) {
Expand All @@ -70,9 +72,20 @@ class CompanyAdapter : BaseRecyclerViewAdapter<Company, RecyclerView.ViewHolder>
var progressBar: ProgressBar = bindView(R.id.progress_bar)
}

fun addLoading() {
if (itemCount > 0) {
isLoading = true
}
}

fun removeLoading() {
if (isLoading) {
isLoading = false
}
}

companion object {
// TODO Не отображается progress bar
private val TYPE_COMPANY = 0
private val TYPE_LOADING = 1
private const val TYPE_COMPANY = 0
private const val TYPE_LOADING = 1
}
}
Loading

0 comments on commit 0f622c2

Please sign in to comment.