-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aded RIS (/labelsearch only) to Image Labelling
- Loading branch information
Showing
11 changed files
with
299 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/bapspatil/rake/adapter/MoreInfoAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.bapspatil.rake.adapter | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bapspatil.rake.R | ||
import com.bapspatil.rake.model.RisOutputModel | ||
import kotlinx.android.synthetic.main.item_text.view.* | ||
import org.jetbrains.anko.browse | ||
|
||
/* | ||
** Created by Bapusaheb Patil {@link https://bapspatil.com} | ||
*/ | ||
|
||
class MoreInfoAdapter(private val mContext: Context, private val mRisOutputModel: RisOutputModel) : RecyclerView.Adapter<MoreInfoAdapter.TextViewHolder>() { | ||
|
||
inner class TextViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) | ||
|
||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): TextViewHolder { | ||
return TextViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_text, viewGroup, false)) | ||
} | ||
|
||
override fun onBindViewHolder(viewHolder: TextViewHolder, position: Int) { | ||
val title = mRisOutputModel.titles?.get(position) | ||
val link = mRisOutputModel.links?.get(position) | ||
viewHolder.itemView.textItemTextView.text = title | ||
viewHolder.itemView.textItemTextView.setOnClickListener { | ||
link?.let { it1 -> mContext.browse(it1) } | ||
} | ||
} | ||
|
||
override fun getItemCount() = mRisOutputModel.titles!!.size | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.bapspatil.rake.ris | ||
|
||
import com.bapspatil.rake.model.RisInputModel | ||
import com.bapspatil.rake.model.RisOutputModel | ||
import retrofit2.Call | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import retrofit2.http.Body | ||
import retrofit2.http.Headers | ||
import retrofit2.http.POST | ||
|
||
/* | ||
** Created by Bapusaheb Patil {@link https://bapspatil.com} | ||
*/ | ||
|
||
interface RisApiService { | ||
|
||
@Headers("Content-Type: application/json") | ||
@POST("labelsearch") | ||
fun getRisInfo(@Body risInputModel: RisInputModel): Call<RisOutputModel> | ||
|
||
companion object { | ||
const val BASE_URL = "https://ris-app.herokuapp.com/" | ||
|
||
fun create(): RisApiService { | ||
val retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
return retrofit.create(RisApiService::class.java) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.bapspatil.rake.ui | ||
|
||
import android.app.ProgressDialog | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.app.NavUtils | ||
import androidx.databinding.DataBindingUtil | ||
import com.bapspatil.rake.R | ||
import com.bapspatil.rake.adapter.MoreInfoAdapter | ||
import com.bapspatil.rake.databinding.ActivityRisBinding | ||
import com.bapspatil.rake.model.RisInputModel | ||
import com.bapspatil.rake.model.RisOutputModel | ||
import com.bapspatil.rake.ris.RisApiService | ||
import com.bapspatil.rake.util.CommonUtils.makeUiLight | ||
import com.bapspatil.rake.util.Constants | ||
import kotlinx.android.synthetic.main.activity_ris.* | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import org.jetbrains.anko.browse | ||
import org.jetbrains.anko.longToast | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
class RisActivity : AppCompatActivity(), CoroutineScope { | ||
private lateinit var binding: ActivityRisBinding | ||
private lateinit var job: Job | ||
override val coroutineContext: CoroutineContext | ||
get() = job + Dispatchers.Main | ||
|
||
private val progressDialog: ProgressDialog by lazy { | ||
ProgressDialog(this) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = DataBindingUtil.setContentView(this, R.layout.activity_ris) | ||
job = Job() | ||
|
||
makeUiLight() | ||
|
||
if (!progressDialog.isShowing) { | ||
progressDialog.setCanceledOnTouchOutside(false) | ||
progressDialog.setMessage("Getting more info...") | ||
progressDialog.setOnCancelListener { | ||
NavUtils.navigateUpFromSameTask(this@RisActivity) | ||
} | ||
progressDialog.show() | ||
} | ||
|
||
val labelForRis = intent.getStringExtra(Constants.KEY_LABEL_FOR_RIS) | ||
if (labelForRis != null) { | ||
val risInputModel = RisInputModel(labelForRis) | ||
RisApiService.create() | ||
.getRisInfo(risInputModel) | ||
.enqueue(object : Callback<RisOutputModel> { | ||
override fun onFailure(call: Call<RisOutputModel>, t: Throwable) { | ||
longToast("Failed to fetch your data!") | ||
if (progressDialog.isShowing) | ||
progressDialog.hide() | ||
NavUtils.navigateUpFromSameTask(this@RisActivity) | ||
} | ||
|
||
override fun onResponse(call: Call<RisOutputModel>, response: Response<RisOutputModel>) { | ||
if (response.isSuccessful && response.body() != null) { | ||
updateUiWithData(response.body()!!) | ||
if (progressDialog.isShowing) | ||
progressDialog.hide() | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
private fun updateUiWithData(risOutputModel: RisOutputModel) { | ||
moreInfoRecyclerView.adapter = MoreInfoAdapter(this, risOutputModel) | ||
googleImagesButton.setOnClickListener { | ||
risOutputModel.images?.get(0)?.let { it1 -> browse(it1) } | ||
} | ||
labelledImagesDashboardButton.setOnClickListener { | ||
browse("https://rake.now.sh/#/dashboard/labelled-images") | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
job.cancel() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp"> | ||
<path android:fillColor="#FFFFFF" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.