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

Commit ca4056e

Browse files
authored
Merge pull request #2093 from karthyks/refactor/app-module
[REFACTOR] Handle nullable on arguments extra
2 parents 99f75dd + d5a5a9b commit ca4056e

43 files changed

Lines changed: 292 additions & 318 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/chat/rocket/android/authentication/login/ui/LoginFragment.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ class LoginFragment : Fragment(), LoginView {
5858
override fun onCreate(savedInstanceState: Bundle?) {
5959
super.onCreate(savedInstanceState)
6060
AndroidSupportInjection.inject(this)
61-
62-
val bundle = arguments
63-
if (bundle != null) {
64-
serverName = bundle.getString(SERVER_NAME)
61+
arguments?.run {
62+
serverName = getString(SERVER_NAME)
6563
}
6664
}
6765

@@ -150,7 +148,7 @@ class LoginFragment : Fragment(), LoginView {
150148
override fun showGenericErrorMessage() = showMessage(R.string.msg_generic_error)
151149

152150
private fun setupOnClickListener() =
153-
ui { _ ->
151+
ui {
154152
button_log_in.setOnClickListener {
155153
presenter.authenticateWithUserAndPassword(
156154
text_username_or_email.textContent,
@@ -160,7 +158,7 @@ class LoginFragment : Fragment(), LoginView {
160158
}
161159

162160
override fun showForgotPasswordView() {
163-
ui { _ ->
161+
ui {
164162
button_forgot_your_password.isVisible = true
165163
button_forgot_your_password.setOnClickListener { presenter.forgotPassword() }
166164

app/src/main/java/chat/rocket/android/authentication/loginoptions/ui/LoginOptionsFragment.kt

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -157,34 +157,33 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
157157
super.onCreate(savedInstanceState)
158158
AndroidSupportInjection.inject(this)
159159

160-
val bundle = arguments
161-
if (bundle != null) {
162-
serverName = bundle.getString(SERVER_NAME)
163-
state = bundle.getString(STATE)
164-
facebookOauthUrl = bundle.getString(FACEBOOK_OAUTH_URL)
165-
githubOauthUrl = bundle.getString(GITHUB_OAUTH_URL)
166-
googleOauthUrl = bundle.getString(GOOGLE_OAUTH_URL)
167-
linkedinOauthUrl = bundle.getString(LINKEDIN_OAUTH_URL)
168-
gitlabOauthUrl = bundle.getString(GITLAB_OAUTH_URL)
169-
wordpressOauthUrl = bundle.getString(WORDPRESS_OAUTH_URL)
170-
casLoginUrl = bundle.getString(CAS_LOGIN_URL)
171-
casToken = bundle.getString(CAS_TOKEN)
172-
casServiceName = bundle.getString(CAS_SERVICE_NAME)
173-
casServiceNameTextColor = bundle.getInt(CAS_SERVICE_NAME_TEXT_COLOR)
174-
casServiceButtonColor = bundle.getInt(CAS_SERVICE_BUTTON_COLOR)
175-
customOauthUrl = bundle.getString(CUSTOM_OAUTH_URL)
176-
customOauthServiceName = bundle.getString(CUSTOM_OAUTH_SERVICE_NAME)
177-
customOauthServiceTextColor = bundle.getInt(CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR)
178-
customOauthServiceButtonColor = bundle.getInt(CUSTOM_OAUTH_SERVICE_BUTTON_COLOR)
179-
samlUrl = bundle.getString(SAML_URL)
180-
samlToken = bundle.getString(SAML_TOKEN)
181-
samlServiceName = bundle.getString(SAML_SERVICE_NAME)
182-
samlServiceTextColor = bundle.getInt(SAML_SERVICE_NAME_TEXT_COLOR)
183-
samlServiceButtonColor = bundle.getInt(SAML_SERVICE_BUTTON_COLOR)
184-
totalSocialAccountsEnabled = bundle.getInt(TOTAL_SOCIAL_ACCOUNTS)
185-
isLoginFormEnabled = bundle.getBoolean(IS_LOGIN_FORM_ENABLED)
186-
isNewAccountCreationEnabled = bundle.getBoolean(IS_NEW_ACCOUNT_CREATION_ENABLED)
187-
deepLinkInfo = bundle.getParcelable(DEEP_LINK_INFO)
160+
arguments?.run {
161+
serverName = getString(SERVER_NAME)
162+
state = getString(STATE)
163+
facebookOauthUrl = getString(FACEBOOK_OAUTH_URL)
164+
githubOauthUrl = getString(GITHUB_OAUTH_URL)
165+
googleOauthUrl = getString(GOOGLE_OAUTH_URL)
166+
linkedinOauthUrl = getString(LINKEDIN_OAUTH_URL)
167+
gitlabOauthUrl = getString(GITLAB_OAUTH_URL)
168+
wordpressOauthUrl = getString(WORDPRESS_OAUTH_URL)
169+
casLoginUrl = getString(CAS_LOGIN_URL)
170+
casToken = getString(CAS_TOKEN)
171+
casServiceName = getString(CAS_SERVICE_NAME)
172+
casServiceNameTextColor = getInt(CAS_SERVICE_NAME_TEXT_COLOR)
173+
casServiceButtonColor = getInt(CAS_SERVICE_BUTTON_COLOR)
174+
customOauthUrl = getString(CUSTOM_OAUTH_URL)
175+
customOauthServiceName = getString(CUSTOM_OAUTH_SERVICE_NAME)
176+
customOauthServiceTextColor = getInt(CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR)
177+
customOauthServiceButtonColor = getInt(CUSTOM_OAUTH_SERVICE_BUTTON_COLOR)
178+
samlUrl = getString(SAML_URL)
179+
samlToken = getString(SAML_TOKEN)
180+
samlServiceName = getString(SAML_SERVICE_NAME)
181+
samlServiceTextColor = getInt(SAML_SERVICE_NAME_TEXT_COLOR)
182+
samlServiceButtonColor = getInt(SAML_SERVICE_BUTTON_COLOR)
183+
totalSocialAccountsEnabled = getInt(TOTAL_SOCIAL_ACCOUNTS)
184+
isLoginFormEnabled = getBoolean(IS_LOGIN_FORM_ENABLED)
185+
isNewAccountCreationEnabled = getBoolean(IS_NEW_ACCOUNT_CREATION_ENABLED)
186+
deepLinkInfo = getParcelable(DEEP_LINK_INFO)
188187
}
189188
}
190189

@@ -388,7 +387,7 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
388387
}
389388

390389
override fun setupExpandAccountsView() {
391-
ui { _ ->
390+
ui {
392391
expand_more_accounts_container.isVisible = true
393392
var isAccountsCollapsed = true
394393
button_expand_collapse_accounts.setOnClickListener {
@@ -406,14 +405,14 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
406405
}
407406

408407
override fun showLoginWithEmailButton() {
409-
ui { _ ->
408+
ui {
410409
button_login_with_email.setOnClickListener { presenter.toLoginWithEmail() }
411410
button_login_with_email.isVisible = true
412411
}
413412
}
414413

415414
override fun showCreateNewAccountButton() {
416-
ui { _ ->
415+
ui {
417416
button_create_an_account.setOnClickListener { presenter.toCreateAccount() }
418417
button_create_an_account.isVisible = true
419418
}

app/src/main/java/chat/rocket/android/authentication/registerusername/ui/RegisterUsernameFragment.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ class RegisterUsernameFragment : Fragment(), RegisterUsernameView {
5252
override fun onCreate(savedInstanceState: Bundle?) {
5353
super.onCreate(savedInstanceState)
5454
AndroidSupportInjection.inject(this)
55-
56-
val bundle = arguments
57-
if (bundle != null) {
58-
userId = bundle.getString(BUNDLE_USER_ID)
59-
authToken = bundle.getString(BUNDLE_AUTH_TOKEN)
60-
} else {
61-
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" }
62-
}
55+
arguments?.run {
56+
userId = getString(BUNDLE_USER_ID, "")
57+
authToken = getString(BUNDLE_AUTH_TOKEN, "")
58+
} ?: requireNotNull(arguments) { "no arguments supplied when the fragment was instantiated" }
6359
}
6460

6561
override fun onCreateView(

app/src/main/java/chat/rocket/android/authentication/signup/ui/SignupFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SignupFragment : Fragment(), SignupView {
7575
}
7676

7777
private fun setupOnClickListener() =
78-
ui { _ ->
78+
ui {
7979
button_register.setOnClickListener {
8080
presenter.signup(
8181
text_username.textContent,

app/src/main/java/chat/rocket/android/authentication/twofactor/ui/TwoFAFragment.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,10 @@ class TwoFAFragment : Fragment(), TwoFAView {
4949
override fun onCreate(savedInstanceState: Bundle?) {
5050
super.onCreate(savedInstanceState)
5151
AndroidSupportInjection.inject(this)
52-
53-
val bundle = arguments
54-
if (bundle != null) {
55-
username = bundle.getString(BUNDLE_USERNAME)
56-
password = bundle.getString(BUNDLE_PASSWORD)
57-
} else {
58-
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" }
59-
}
52+
arguments?.run {
53+
username = getString(BUNDLE_USERNAME, "")
54+
password = getString(BUNDLE_PASSWORD, "")
55+
} ?: requireNotNull(arguments) { "no arguments supplied when the fragment was instantiated" }
6056
}
6157

6258
override fun onCreateView(

app/src/main/java/chat/rocket/android/chatdetails/ui/ChatDetailsFragment.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ class ChatDetailsFragment : Fragment(), ChatDetailsView {
6666
override fun onCreate(savedInstanceState: Bundle?) {
6767
super.onCreate(savedInstanceState)
6868
AndroidSupportInjection.inject(this)
69-
val bundle = arguments
70-
if (bundle != null) {
71-
chatRoomId = bundle.getString(BUNDLE_CHAT_ROOM_ID)
72-
chatRoomType = bundle.getString(BUNDLE_CHAT_ROOM_TYPE)
73-
isSubscribed = bundle.getBoolean(BUNDLE_IS_SUBSCRIBED)
74-
disableMenu = bundle.getBoolean(BUNDLE_DISABLE_MENU)
75-
} else {
76-
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" }
77-
}
69+
arguments?.run {
70+
chatRoomId = getString(BUNDLE_CHAT_ROOM_ID)
71+
chatRoomType = getString(BUNDLE_CHAT_ROOM_TYPE)
72+
isSubscribed = getBoolean(BUNDLE_IS_SUBSCRIBED)
73+
disableMenu = getBoolean(BUNDLE_DISABLE_MENU)
74+
} ?: requireNotNull(arguments) { "no arguments supplied when the fragment was instantiated" }
7875
}
7976

8077
override fun onCreateView(

app/src/main/java/chat/rocket/android/chatinformation/ui/MessageInfoFragment.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ class MessageInfoFragment : Fragment(), MessageInfoView {
4646
AndroidSupportInjection.inject(this)
4747
setHasOptionsMenu(true)
4848

49-
val bundle = arguments
50-
if (bundle != null) {
51-
messageId = bundle.getString(BUNDLE_MESSAGE_ID)
52-
} else {
53-
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" }
54-
}
49+
arguments?.run {
50+
messageId = getString(BUNDLE_MESSAGE_ID, "")
51+
} ?: requireNotNull(arguments) { "no arguments supplied when the fragment was instantiated" }
5552
}
5653

5754
override fun onCreateView(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import com.facebook.drawee.backends.pipeline.Fresco
1212
import kotlinx.android.synthetic.main.item_action_button.view.*
1313
import timber.log.Timber
1414

15-
class ActionsListAdapter(actions: List<Action>, var actionAttachmentOnClickListener: ActionAttachmentOnClickListener) : RecyclerView.Adapter<ActionsListAdapter.ViewHolder>() {
15+
class ActionsListAdapter(
16+
actions: List<Action>,
17+
var actionAttachmentOnClickListener: ActionAttachmentOnClickListener
18+
) : RecyclerView.Adapter<ActionsListAdapter.ViewHolder>() {
1619

1720
var actions: List<Action> = actions
1821

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ class ChatRoomAdapter(
174174
Timber.d("index: $index")
175175
if (index > -1) {
176176
dataSet[index] = message
177-
dataSet.forEachIndexed { index, viewModel ->
177+
dataSet.forEachIndexed { ind, viewModel ->
178178
if (viewModel.messageId == message.messageId) {
179179
if (viewModel.nextDownStreamMessage == null) {
180180
viewModel.reactions = message.reactions
181181
}
182-
notifyItemChanged(index)
182+
notifyItemChanged(ind)
183183
}
184184
}
185185
// Delete message only if current is a system message update, i.e.: Message Removed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class RoomSuggestionsAdapter : SuggestionsAdapter<RoomSuggestionsViewHolder>("#"
2424
override fun bind(item: SuggestionModel, itemClickListener: SuggestionsAdapter.ItemClickListener?) {
2525
item as ChatRoomSuggestionUiModel
2626
with(itemView) {
27-
val fullname = itemView.findViewById<TextView>(R.id.text_fullname)
28-
val name = itemView.findViewById<TextView>(R.id.text_name)
27+
val fullname = findViewById<TextView>(R.id.text_fullname)
28+
val name = findViewById<TextView>(R.id.text_name)
2929
name.text = item.name
3030
fullname.text = item.fullName
3131
setOnClickListener {

0 commit comments

Comments
 (0)