Skip to content

Commit

Permalink
Merge pull request #108 from raghunandankavi2010/Resolve-some-lintwar…
Browse files Browse the repository at this point in the history
…nings

Issue #107 Resolve - Some Lint warnings.
  • Loading branch information
Mauker1 authored Dec 30, 2018
2 parents a521f6e + ae40b7d commit 4df2e99
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 111 deletions.
10 changes: 2 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ dependencies {

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.30.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0-alpha'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.0-alpha'

// Glide
implementation "com.github.bumptech.glide:glide:$glide"
Expand All @@ -87,9 +87,3 @@ dependencies {
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlin"
testImplementation "com.squareup.okhttp:mockwebserver:$mockWebServer"
}

kotlin {
experimental {
coroutines = 'enable'
}
}
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.tristanwiley.chatse">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -10,7 +11,8 @@
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".splash.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -41,7 +43,9 @@
<!-- android:scheme="https" /> -->
<!-- </intent-filter> -->
</activity>
<activity android:name=".about.AboutActivity" />
<activity
android:theme="@style/AppTheme.About"
android:name=".about.AboutActivity" />

<service
android:name=".chat.service.IncomingEventService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ class AboutActivity : AppCompatActivity() {
AlertDialog.Builder(ContextThemeWrapper(this, R.style.AppTheme_SO))
.setTitle(getString(R.string.about_app_header_changelog))
.setView(R.layout.fragment_changelog)
.setPositiveButton("Close",
{ dialog, _ -> dialog.dismiss() }
)
.setPositiveButton("Close") { dialog, _ -> dialog.dismiss() }
.create()
.show()
}
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/tristanwiley/chatse/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.Toolbar
import android.text.InputType
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.Menu
import android.view.MenuItem
Expand All @@ -43,6 +42,7 @@ import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.json.JSONException
import org.json.JSONObject
import timber.log.Timber
import java.io.IOException

/**
Expand Down Expand Up @@ -138,15 +138,15 @@ class ChatActivity : AppCompatActivity(), ServiceConnection, RoomAdapter.OnItemC
userEmail.text = prefs.getString("email", "")
}
}
else -> Log.e("ChatActivity", "Userid not found")
else -> Timber.e("ChatActivity UserId not found")
}
}

/**
* When network is connected add the rooms to the drawer
*/
override fun onServiceConnected(name: ComponentName, binder: IBinder) {
Log.d("onServiceConnected", "Service connect")
Timber.d("onServiceConnected Service connect")
serviceBinder = binder as IncomingEventServiceBinder

//Asynchronously add rooms to drawer
Expand All @@ -157,7 +157,7 @@ class ChatActivity : AppCompatActivity(), ServiceConnection, RoomAdapter.OnItemC

//Load a default room

loadChatFragment(ChatRoom(prefs.getString(RoomPreferenceKeys.LAST_ROOM_SITE, Client.SITE_STACK_OVERFLOW), prefs.getInt(RoomPreferenceKeys.LAST_ROOM_NUM, 15)))
loadChatFragment(ChatRoom(prefs.getString(RoomPreferenceKeys.LAST_ROOM_SITE, Client.SITE_STACK_OVERFLOW)!!, prefs.getInt(RoomPreferenceKeys.LAST_ROOM_NUM, 15)))
currentRoomNum = prefs.getInt(RoomPreferenceKeys.LAST_ROOM_NUM, 15)
}

Expand Down Expand Up @@ -208,7 +208,7 @@ class ChatActivity : AppCompatActivity(), ServiceConnection, RoomAdapter.OnItemC
.build()
val response = client.newCall(soChatPageRequest).execute()
val jsonData = response.body().string()
Log.wtf("JSON", jsonData)
Timber.wtf("JSON $jsonData")
val result = JSONObject(jsonData)

runOnUiThread {
Expand Down Expand Up @@ -426,7 +426,7 @@ class ChatActivity : AppCompatActivity(), ServiceConnection, RoomAdapter.OnItemC
}

override fun onServiceDisconnected(name: ComponentName) {
Log.d("ChatActivity", "Service disconnect")
Timber.d("ChatActivity Service disconnect")
}

override fun onItemClick(chatRoom: ChatRoom) {
Expand Down
27 changes: 9 additions & 18 deletions app/src/main/java/com/tristanwiley/chatse/chat/ChatFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import android.support.v7.widget.RecyclerView
import android.text.Html
import android.text.util.Linkify
import android.util.Base64
import android.util.Log
import android.view.*
import android.widget.EditText
import android.widget.LinearLayout
Expand Down Expand Up @@ -51,6 +50,7 @@ import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.json.JSONObject
import org.jsoup.Jsoup
import timber.log.Timber
import java.io.ByteArrayOutputStream
import java.io.FileNotFoundException
import java.io.IOException
Expand Down Expand Up @@ -181,11 +181,7 @@ class ChatFragment : Fragment(), IncomingEventListener, ChatMessageCallback {
//When you click on the gallery button, open a camera intent and get the result in onActivityResult
//Request external storage permission
if (ContextCompat.checkSelfPermission(activity as ChatActivity, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ActivityCompat.requestPermissions(activity as ChatActivity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 0)
} else {
openFileChooser()
}
} else {
openFileChooser()
}
Expand Down Expand Up @@ -343,12 +339,7 @@ class ChatFragment : Fragment(), IncomingEventListener, ChatMessageCallback {
tagview.layoutParams = layoutparam

//Set the background to a rectangle to look like it does on the web
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
tagview.background = ContextCompat.getDrawable(context as Context, R.drawable.tag_background)
} else {
@Suppress("DEPRECATION")
tagview.setBackgroundDrawable(ContextCompat.getDrawable(context as Context, R.drawable.tag_background))
}
tagview.background = ContextCompat.getDrawable(context as Context, R.drawable.tag_background)

//Add the tag to the layout
tagsLayout.addView(tagview)
Expand Down Expand Up @@ -511,7 +502,7 @@ class ChatFragment : Fragment(), IncomingEventListener, ChatMessageCallback {
try {
newMessage(client, room, chatFkey, content)
} catch (e: IOException) {
Log.e("handleNewEvents", e.message)
Timber.e("handleNewEvents ${e.message}")
}
}
}
Expand Down Expand Up @@ -616,15 +607,15 @@ class ChatFragment : Fragment(), IncomingEventListener, ChatMessageCallback {

companion object {

private val EXTRA_ROOM = "room"
private val EXTRA_NAME = "name"
private val EXTRA_FKEY = "fkey"
private const val EXTRA_ROOM = "room"
private const val EXTRA_NAME = "name"
private const val EXTRA_FKEY = "fkey"

fun createInstance(room: ChatRoom, name: String, fkey: String): ChatFragment {
val b = Bundle(3)
b.putParcelable(ChatFragment.Companion.EXTRA_ROOM, room)
b.putString(ChatFragment.Companion.EXTRA_NAME, name)
b.putString(ChatFragment.Companion.EXTRA_FKEY, fkey)
b.putParcelable(ChatFragment.EXTRA_ROOM, room)
b.putString(ChatFragment.EXTRA_NAME, name)
b.putString(ChatFragment.EXTRA_FKEY, fkey)

val fragment = ChatFragment()
fragment.arguments = b
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/tristanwiley/chatse/chat/ChatRoom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.os.Parcelable
*/
class ChatRoom(val site: String, val num: Int) : Parcelable {

private constructor(source: Parcel) : this(source.readString(), source.readInt())
private constructor(source: Parcel) : this(source.readString()!!, source.readInt())

override fun toString(): String {
return "Room $num"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DividerItemDecoration @JvmOverloads constructor(

init {
val attrs = context.obtainStyledAttributes(ATTRS)
divider = attrs.getDrawable(DIVIDER_POSITION)
divider = attrs.getDrawable(DIVIDER_POSITION)!!
attrs.recycle()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import android.text.SpannableString
import android.text.Spanned
import android.text.style.QuoteSpan
import android.text.util.Linkify
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -262,7 +261,12 @@ class MessageAdapter(
Timber.i("Message Content :${message.content}")
val content = message.content!!.replaceFirst("> ","")
val spanString = SpannableString(content)
spanString.setSpan(QuoteSpan(ContextCompat.getColor(mContext,R.color.color_accent), 5, 40), 0, spanString.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
// QuoteSpan with constructor with color, stripeWidth and gapWidth only available in api 28
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
spanString.setSpan(QuoteSpan(ContextCompat.getColor(mContext, R.color.color_accent), 5, 40), 0, spanString.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
} else {
spanString.setSpan(QuoteSpan(ContextCompat.getColor(mContext, R.color.color_accent)), 0, spanString.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
messageView.text = spanString
} else{
messageView.setTextColor(ContextCompat.getColor(itemView.context, R.color.primary_text))
Expand Down Expand Up @@ -377,7 +381,7 @@ class MessageAdapter(
messageView.setPadding(15, 15, 15, 15)
messageView.setTextColor(ContextCompat.getColor(itemView.context, R.color.white))
messageView.setLinkTextColor(ContextCompat.getColor(itemView.context, R.color.accent_twitter))
Log.d("Onebox", "Type: ${message.oneboxType}")
Timber.d("Onebox Type: ${message.oneboxType}")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
messageView.text = Html.fromHtml(message.content, Html.FROM_HTML_MODE_LEGACY)
} else {
Expand All @@ -388,7 +392,7 @@ class MessageAdapter(
}
//Other oneboxed items just display the HTML until we implement them all
else -> {
Log.d("Onebox", "Type: ${message.oneboxType}")
Timber.d("Onebox Type: ${message.oneboxType}")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
messageView.text = Html.fromHtml(message.content, Html.FROM_HTML_MODE_LEGACY)
} else {
Expand Down Expand Up @@ -493,7 +497,7 @@ class MessageAdapter(
* Function to edit the message
* @param message: MessageEvent of the message to edit
* @param mContext: Application context
* @param plusDialog: DialogPlus so we can dismiss
* plusDialog: DialogPlus so we can dismiss
*/
private fun showEditDialog(message: MessageEvent, mContext: Context) {
//Create AlertDialog
Expand Down Expand Up @@ -562,7 +566,7 @@ class MessageAdapter(
fun getDominantColor(bitmap: Bitmap): Int {
val swatchesTemp = Palette.from(bitmap).generate().swatches
val swatches = ArrayList<Palette.Swatch>(swatchesTemp)
Collections.sort(swatches) { swatch1, swatch2 -> swatch2.population - swatch1.population }
swatches.sortWith(Comparator { swatch1, swatch2 -> swatch2.population - swatch1.population })
return if (swatches.size > 0) swatches[0].rgb else ContextCompat.getColor(mContext, (R.color.primary))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.widget.TextView
import com.squareup.okhttp.FormEncodingBuilder
import com.squareup.okhttp.Request
import com.tristanwiley.chatse.R
import com.tristanwiley.chatse.chat.ChatActivity
import com.tristanwiley.chatse.chat.ChatRoom
import com.tristanwiley.chatse.chat.Room
import com.tristanwiley.chatse.network.ClientManager
Expand Down Expand Up @@ -72,17 +71,17 @@ class RoomAdapter(val site: String, val list: MutableList<Room>, val context: Co
AlertDialog.Builder(mContext)
.setTitle("Modify Room")
.setMessage("Would you like to modify room #${room.roomID}, ${room.name}?")
.setPositiveButton("Leave Room", { dialog, _ ->
.setPositiveButton("Leave Room") { dialog, _ ->
leaveRoom(room.roomID, room.fkey)
dialog.dismiss()
})
.setNegativeButton(favoriteToggleString, { dialog, _ ->
}
.setNegativeButton(favoriteToggleString) { dialog, _ ->
toggleFavoriteRoom(room, room.fkey)
dialog.dismiss()
})
.setNeutralButton("Cancel", { dialog, _ ->
}
.setNeutralButton("Cancel") { dialog, _ ->
dialog.cancel()
})
}
.show()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ class UsersAdapter(private val mContext: Context, private val events: EventList,
builder.setView(layout)

//Create cancel button to cancel dialog
builder.setNegativeButton("Cancel", { dialog, _ ->
builder.setNegativeButton("Cancel") { dialog, _ ->
dialog.cancel()
})
}

//Show Dialog
builder.show()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.tristanwiley.chatse.chat.service

import android.util.Log
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.squareup.okhttp.Response
import com.squareup.okhttp.ws.WebSocket
import com.squareup.okhttp.ws.WebSocketListener
import okio.Buffer
import okio.BufferedSource
import timber.log.Timber

import java.io.IOException

Expand All @@ -18,7 +18,7 @@ class ChatWebSocketListener(private val site: String, private val listener: Chat
private val mapper = ObjectMapper()

override fun onOpen(webSocket: WebSocket, response: Response) {
Log.i("ChatWebSocketListener", "websocket open: " + site)
Timber.i("ChatWebSocketListener websocket open: $site")
listener.onConnect(site, true)
}

Expand All @@ -35,17 +35,17 @@ class ChatWebSocketListener(private val site: String, private val listener: Chat
val root = mapper.readTree(message)
listener.onNewEvents(site, root)
} catch (e: IOException) {
Log.e("ChatWebSocketListener", e.message)
Timber.e("ChatWebSocketListener${e.message}")
}

}

override fun onPong(payload: Buffer) {
Log.i("ChatWebSocketListener", "websocket pong: $site")
Timber.i("ChatWebSocketListener web socket pong: $site")
}

override fun onClose(code: Int, reason: String) {
Log.i("ChatWebSocketListener", "websocket close: $site: $code, $reason")
Timber.i("ChatWebSocketListenerweb socket close: $site: $code, $reason")
}

interface ServiceWebsocketListener {
Expand Down
Loading

0 comments on commit 4df2e99

Please sign in to comment.