-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- menambah activity untuk search match
- Loading branch information
Showing
18 changed files
with
318 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 2 additions & 0 deletions
2
app/src/main/java/com/example/wijaya_pc/footballapps/adapter/SearchMatchAdapter.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,2 @@ | ||
package com.example.wijaya_pc.footballapps.adapter | ||
|
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
119 changes: 119 additions & 0 deletions
119
app/src/main/java/com/example/wijaya_pc/footballapps/feature/match/SearchMatchActivity.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,119 @@ | ||
package com.example.wijaya_pc.footballapps.feature.match | ||
|
||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.support.v4.widget.SwipeRefreshLayout | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.support.v7.widget.RecyclerView | ||
import android.support.v7.widget.SearchView | ||
import android.support.v7.widget.Toolbar | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import android.widget.ProgressBar | ||
import com.example.wijaya_pc.footballapps.R | ||
import com.example.wijaya_pc.footballapps.R.menu.search_menu | ||
import com.example.wijaya_pc.footballapps.adapter.MatchAdapter | ||
import com.example.wijaya_pc.footballapps.api.ApiRepository | ||
import com.example.wijaya_pc.footballapps.invisible | ||
import com.example.wijaya_pc.footballapps.model.Match | ||
import com.example.wijaya_pc.footballapps.presenter.MatchPresenter | ||
import com.example.wijaya_pc.footballapps.presenter.SearchMatchPresenter | ||
import com.example.wijaya_pc.footballapps.view.SearchMatchView | ||
import com.example.wijaya_pc.footballapps.visible | ||
import com.google.gson.Gson | ||
import org.jetbrains.anko.ctx | ||
import org.jetbrains.anko.find | ||
import org.jetbrains.anko.startActivity | ||
import org.jetbrains.anko.support.v4.onRefresh | ||
import org.jetbrains.anko.toast | ||
|
||
class SearchMatchActivity : AppCompatActivity(), SearchMatchView { | ||
private lateinit var toolbar: Toolbar | ||
|
||
private lateinit var recyclerView: RecyclerView | ||
private lateinit var searchView : SearchView | ||
private lateinit var progressBar : ProgressBar | ||
|
||
private var matches: MutableList<Match> = mutableListOf() | ||
|
||
private lateinit var matchAdapter: MatchAdapter | ||
|
||
private lateinit var presenter: SearchMatchPresenter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_search_match) | ||
|
||
toolbar = find(R.id.toolbar_search) | ||
recyclerView = find(R.id.rv_search) | ||
progressBar = find(R.id.progress_bar_search) | ||
|
||
setSupportActionBar(toolbar) | ||
supportActionBar?.title = "Search Match" | ||
supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
|
||
val request = ApiRepository() | ||
val gson = Gson() | ||
presenter = SearchMatchPresenter(this, request, gson) | ||
|
||
recyclerView.layoutManager = LinearLayoutManager(ctx) | ||
matchAdapter = MatchAdapter(matches) { | ||
ctx.startActivity<DetailMatchActivity>( | ||
"id" to "${it.matchId}", | ||
"homeTeamId" to "${it.idHomeTeam}", | ||
"awayTeamId" to "${it.idAwayTeam}" | ||
) | ||
} | ||
recyclerView.adapter = matchAdapter | ||
|
||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
menuInflater.inflate(search_menu, menu) | ||
|
||
val searchMenu = menu.findItem(R.id.action_search) | ||
searchMenu.expandActionView() | ||
searchView = searchMenu.actionView as SearchView | ||
searchView.queryHint = "Search" | ||
|
||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { | ||
override fun onQueryTextSubmit(query: String?): Boolean { | ||
presenter.getSearchMatch(query) | ||
|
||
return false | ||
} | ||
|
||
override fun onQueryTextChange(newText: String?): Boolean { | ||
return false | ||
} | ||
|
||
}) | ||
|
||
return true | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
return when (item.itemId) { | ||
android.R.id.home -> { | ||
finish() | ||
true | ||
} | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
|
||
override fun showLoading() { | ||
progressBar.visible() | ||
} | ||
|
||
override fun hideLoading() { | ||
progressBar.invisible() | ||
} | ||
|
||
override fun showSearchMatchList(data: List<Match>) { | ||
matches.clear() | ||
matches.addAll(data) | ||
matchAdapter.notifyDataSetChanged() | ||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/example/wijaya_pc/footballapps/presenter/SearchMatchPresenter.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,33 @@ | ||
package com.example.wijaya_pc.footballapps.presenter | ||
|
||
import com.example.wijaya_pc.footballapps.api.ApiRepository | ||
import com.example.wijaya_pc.footballapps.api.TheSportDBApi | ||
import com.example.wijaya_pc.footballapps.coroutine.CoroutineContextProvider | ||
import com.example.wijaya_pc.footballapps.model.MatchResponse | ||
import com.example.wijaya_pc.footballapps.model.SearchMatchResponse | ||
import com.example.wijaya_pc.footballapps.view.SearchMatchView | ||
import com.google.gson.Gson | ||
import kotlinx.coroutines.experimental.async | ||
import org.jetbrains.anko.coroutines.experimental.bg | ||
|
||
class SearchMatchPresenter( | ||
private val view: SearchMatchView, | ||
private val apiRepository: ApiRepository, | ||
private val gson: Gson, | ||
private val context: CoroutineContextProvider = CoroutineContextProvider() | ||
) { | ||
fun getSearchMatch(matchName: String?) { | ||
view.showLoading() | ||
|
||
async(context.main) { | ||
val data = bg { | ||
gson.fromJson( | ||
apiRepository.doRequest(TheSportDBApi.getSearchMatch(matchName)), | ||
SearchMatchResponse::class.java | ||
) | ||
} | ||
view.showSearchMatchList(data.await().event) | ||
view.hideLoading() | ||
} | ||
} | ||
} |
Oops, something went wrong.