Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit a9009ba

Browse files
committed
Merge branch 'develop' into beta
2 parents a9985b2 + 69af388 commit a9009ba

30 files changed

Lines changed: 239 additions & 34 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This repository contains all the code related to the Android native application
1111

1212
## How to build
1313

14-
- You need to download the latest [Android Studio Preview](https://developer.android.com/studio/preview/) version since the stable IDE version does not support the [JetPack](https://developer.android.com/jetpack/) that is beeing used on this application.
14+
- You need to download the latest [Android Studio Preview](https://developer.android.com/studio/preview/) version since the stable IDE version does not support the [JetPack](https://developer.android.com/jetpack/) that is being used on this application.
1515
- Make sure that you have the latest **gradle** and the **android plugin** versions installed. Go to `File > Project Structure > Project` and make sure that you have the latest versions installed. Refer [this](https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle) to see the compatible versions.
1616
- Kotlin is already configured in the project. To check, go to `Tools > Kotlin > Configure Kotlin in project`. A message saying kotlin is already configured in the project pops up. You can update kotlin to the latest version by going to `Tools > Kotlin > Configure Kotlin updates` and download the latest version of kotlin.
1717

app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class ServerFragment : Fragment(), ServerView {
245245
serverUrlDisposable = text_server_url.asObservable()
246246
.filter { it.isNotBlank() }
247247
.subscribe {
248-
if (it.toString().isValidUrl()) {
248+
if ("$protocol${it.toString()}".isValidUrl()) {
249249
enableButtonConnect()
250250
} else {
251251
disableButtonConnect()

app/src/main/java/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import chat.rocket.android.util.extensions.toList
1818
import chat.rocket.core.model.Message
1919
import chat.rocket.core.model.isSystemMessage
2020
import com.google.android.flexbox.FlexDirection
21+
import com.google.android.flexbox.FlexWrap
2122
import com.google.android.flexbox.FlexboxLayoutManager
23+
import com.google.android.flexbox.JustifyContent
2224

2325
abstract class BaseViewHolder<T : BaseUiModel<*>>(
2426
itemView: View,
@@ -41,13 +43,12 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
4143
private fun bindReactions() {
4244
data?.let {
4345
val recyclerView = itemView.findViewById(R.id.recycler_view_reactions) as RecyclerView
44-
val adapter: MessageReactionsAdapter
45-
if (recyclerView.adapter == null) {
46-
adapter = MessageReactionsAdapter()
46+
val adapter: MessageReactionsAdapter = if (recyclerView.adapter == null) {
47+
MessageReactionsAdapter()
4748
} else {
48-
adapter = recyclerView.adapter as MessageReactionsAdapter
49-
adapter.clear()
49+
recyclerView.adapter as MessageReactionsAdapter
5050
}
51+
adapter.clear()
5152

5253
if (it.nextDownStreamMessage == null) {
5354
adapter.listener = object : EmojiReactionListener {
@@ -61,13 +62,16 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
6162
}
6263
}
6364
}
65+
6466
val context = itemView.context
6567
val manager = FlexboxLayoutManager(context, FlexDirection.ROW)
68+
manager.justifyContent = JustifyContent.FLEX_START
6669
recyclerView.layoutManager = manager
6770
recyclerView.adapter = adapter
68-
adapter.addReactions(it.reactions.filterNot { reactionUiModel ->
69-
reactionUiModel.unicode.startsWith(":") && reactionUiModel.url.isNullOrEmpty()
70-
})
71+
72+
if (it.reactions.isNotEmpty()) {
73+
itemView.post { adapter.addReactions(it.reactions) }
74+
}
7175
}
7276
}
7377
}
@@ -129,4 +133,4 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
129133
}
130134
return true
131135
}
132-
}
136+
}

app/src/main/java/chat/rocket/android/chatroom/adapter/MessageReactionsAdapter.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.view.LayoutInflater
44
import android.view.View
55
import android.view.ViewGroup
66
import android.widget.ImageView
7-
import android.widget.TextView
87
import androidx.core.content.ContextCompat
98
import androidx.recyclerview.widget.RecyclerView
109
import chat.rocket.android.R
@@ -35,17 +34,17 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
3534
}
3635
else -> {
3736
view = inflater.inflate(R.layout.item_reaction, parent, false)
38-
SingleReactionViewHolder(view, listener)
37+
ReactionViewHolder(view, listener)
3938
}
4039
}
4140
}
4241

4342
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
44-
if (holder is SingleReactionViewHolder) {
43+
if (holder is ReactionViewHolder) {
4544
holder.bind(reactions[position])
4645
} else {
4746
holder as AddReactionViewHolder
48-
holder.bind(reactions[0].messageId)
47+
holder.bind(reactions.first().messageId)
4948
}
5049
}
5150

@@ -73,7 +72,7 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
7372
fun contains(reactionShortname: String) =
7473
reactions.firstOrNull { it.shortname == reactionShortname } != null
7574

76-
class SingleReactionViewHolder(
75+
class ReactionViewHolder(
7776
view: View,
7877
private val listener: EmojiReactionListener?
7978
) : RecyclerView.ViewHolder(view), View.OnClickListener {
@@ -97,9 +96,11 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
9796
this.reaction = reaction
9897
with(itemView) {
9998
if (reaction.url.isNullOrEmpty()) {
100-
text_emoji.text = reaction.unicode
99+
// The view at index 0 corresponds to the one to display unicode text emoji.
101100
view_flipper_reaction.displayedChild = 0
101+
text_emoji.text = reaction.unicode
102102
} else {
103+
// The view at index 1 corresponds to the one to display custom emojis which are images.
103104
view_flipper_reaction.displayedChild = 1
104105
val glideRequest = if (reaction.url!!.endsWith("gif", true)) {
105106
GlideApp.with(context).asGif()
@@ -110,15 +111,16 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
110111
glideRequest.load(reaction.url).into(image_emoji)
111112
}
112113

113-
text_count.text = reaction.count.toString()
114114
val myself = localRepository.get(LocalRepository.CURRENT_USERNAME_KEY)
115115
if (reaction.usernames.contains(myself)) {
116116
val context = itemView.context
117117
text_count.setTextColor(ContextCompat.getColor(context, R.color.colorAccent))
118118
}
119119

120-
view_flipper_reaction.setOnClickListener(this@SingleReactionViewHolder)
121-
text_count.setOnClickListener(this@SingleReactionViewHolder)
120+
text_count.text = reaction.count.toString()
121+
122+
view_flipper_reaction.setOnClickListener(this@ReactionViewHolder)
123+
text_count.setOnClickListener(this@ReactionViewHolder)
122124
}
123125
}
124126

app/src/main/java/chat/rocket/android/dagger/LocalComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface LocalComponent {
1919
fun build(): LocalComponent
2020
}
2121

22-
fun inject(adapter: MessageReactionsAdapter.SingleReactionViewHolder)
22+
fun inject(adapter: MessageReactionsAdapter.ReactionViewHolder)
2323
fun inject(adapter: MessageReactionsAdapter.AddReactionViewHolder)
2424

2525
/*@Component.Builder

app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ import chat.rocket.android.server.domain.PermissionsRepository
4040
import chat.rocket.android.server.domain.SettingsRepository
4141
import chat.rocket.android.server.domain.TokenRepository
4242
import chat.rocket.android.server.domain.UsersRepository
43+
import chat.rocket.android.server.domain.BasicAuthRepository
44+
import chat.rocket.android.server.domain.GetBasicAuthInteractor
45+
import chat.rocket.android.server.domain.SaveBasicAuthInteractor
46+
import chat.rocket.android.server.infraestructure.SharedPrefsBasicAuthRepository
4347
import chat.rocket.android.server.infraestructure.DatabaseMessageMapper
4448
import chat.rocket.android.server.infraestructure.DatabaseMessagesRepository
4549
import chat.rocket.android.server.infraestructure.JobSchedulerInteractorImpl
@@ -53,6 +57,7 @@ import chat.rocket.android.server.infraestructure.SharedPrefsConnectingServerRep
5357
import chat.rocket.android.server.infraestructure.SharedPrefsCurrentServerRepository
5458
import chat.rocket.android.util.AppJsonAdapterFactory
5559
import chat.rocket.android.util.HttpLoggingInterceptor
60+
import chat.rocket.android.util.BasicAuthenticatorInterceptor
5661
import chat.rocket.android.util.TimberLogger
5762
import chat.rocket.common.internal.FallbackSealedClassJsonAdapter
5863
import chat.rocket.common.internal.ISO8601Date
@@ -106,9 +111,22 @@ class AppModule {
106111

107112
@Provides
108113
@Singleton
109-
fun provideOkHttpClient(logger: HttpLoggingInterceptor): OkHttpClient {
114+
fun provideBasicAuthenticatorInterceptor(
115+
getBasicAuthInteractor: GetBasicAuthInteractor,
116+
saveBasicAuthInteractor: SaveBasicAuthInteractor
117+
): BasicAuthenticatorInterceptor {
118+
return BasicAuthenticatorInterceptor(
119+
getBasicAuthInteractor,
120+
saveBasicAuthInteractor
121+
)
122+
}
123+
124+
@Provides
125+
@Singleton
126+
fun provideOkHttpClient(logger: HttpLoggingInterceptor, basicAuthenticator: BasicAuthenticatorInterceptor): OkHttpClient {
110127
return OkHttpClient.Builder()
111128
.addInterceptor(logger)
129+
.addInterceptor(basicAuthenticator)
112130
.connectTimeout(15, TimeUnit.SECONDS)
113131
.readTimeout(20, TimeUnit.SECONDS)
114132
.writeTimeout(15, TimeUnit.SECONDS)
@@ -273,6 +291,14 @@ class AppModule {
273291
return MessageParser(context, configuration, settingsInteractor.get(url))
274292
}
275293

294+
@Provides
295+
@Singleton
296+
fun provideBasicAuthRepository (
297+
preferences: SharedPreferences,
298+
moshi: Moshi
299+
): BasicAuthRepository =
300+
SharedPrefsBasicAuthRepository(preferences, moshi)
301+
276302
@Provides
277303
@Singleton
278304
fun provideAccountsRepository(

app/src/main/java/chat/rocket/android/db/MessageDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class MessageDao {
4040
@Insert(onConflict = OnConflictStrategy.REPLACE)
4141
abstract fun insert(field: AttachmentFieldEntity)
4242

43-
@Insert(onConflict = OnConflictStrategy.IGNORE)
43+
@Insert(onConflict = OnConflictStrategy.REPLACE)
4444
abstract fun insert(reaction: ReactionEntity)
4545

4646
@Insert(onConflict = OnConflictStrategy.REPLACE)

app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package chat.rocket.android.main.presentation
22

33
import android.content.Context
4+
import chat.rocket.android.R
45
import chat.rocket.android.core.lifecycle.CancelStrategy
56
import chat.rocket.android.db.DatabaseManagerFactory
67
import chat.rocket.android.emoji.Emoji

app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
232232
toolbar.setNavigationOnClickListener { openDrawer() }
233233
}
234234

235+
fun showLogoutDialog() {
236+
val builder = AlertDialog.Builder(this)
237+
builder.setTitle(R.string.action_logout)
238+
builder.setMessage(R.string.title_confirmation)
239+
builder.setPositiveButton(R.string.action_logout) { _, _ -> presenter.logout()}
240+
.setNegativeButton(R.string.action_stay) { dialog, _ -> dialog.cancel() }
241+
builder.create().show()
242+
}
243+
235244
fun setAvatar(avatarUrl: String) {
236245
headerLayout.image_avatar.setImageURI(avatarUrl)
237246
}

app/src/main/java/chat/rocket/android/main/ui/Menu.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ internal fun MainActivity.onNavDrawerItemSelected(menuItem: MenuItem) {
6464
R.id.menu_action_profile -> presenter.toUserProfile()
6565
R.id.menu_action_settings -> presenter.toSettings()
6666
R.id.menu_action_admin_panel -> presenter.toAdminPanel()
67-
R.id.menu_action_logout -> presenter.logout()
67+
R.id.menu_action_logout -> showLogoutDialog()
6868
}
6969
}

0 commit comments

Comments
 (0)