-
Notifications
You must be signed in to change notification settings - Fork 553
feat: add event types for search #1521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iamareebjamal
merged 1 commit into
fossasia:development
from
aggarwalpulkit596:eventTypes
Apr 7, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/fossasia/openevent/general/event/types/EventType.kt
This file contains hidden or 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,17 @@ | ||
package org.fossasia.openevent.general.event.types | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.github.jasminb.jsonapi.LongIdHandler | ||
import com.github.jasminb.jsonapi.annotations.Id | ||
import com.github.jasminb.jsonapi.annotations.Type | ||
|
||
@Type("event-type") | ||
@Entity | ||
data class EventType( | ||
@Id(LongIdHandler::class) | ||
@PrimaryKey | ||
val id: Long?, | ||
val name: String?, | ||
val slug: String? | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/fossasia/openevent/general/event/types/EventTypesApi.kt
This file contains hidden or 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,10 @@ | ||
package org.fossasia.openevent.general.event.types | ||
|
||
import io.reactivex.Single | ||
import retrofit2.http.GET | ||
|
||
interface EventTypesApi { | ||
|
||
@GET("event-types?sort=name") | ||
fun getEventTypes(): Single<List<EventType>> | ||
} |
This file contains hidden or 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 hidden or 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
57 changes: 57 additions & 0 deletions
57
app/src/main/java/org/fossasia/openevent/general/search/SearchTypeFragment.kt
This file contains hidden or 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,57 @@ | ||
package org.fossasia.openevent.general.search | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.Observer | ||
import androidx.navigation.NavOptions | ||
import androidx.navigation.Navigation | ||
import androidx.navigation.fragment.navArgs | ||
import kotlinx.android.synthetic.main.fragment_search_type.view.eventTypesLv | ||
import org.fossasia.openevent.general.R | ||
import org.fossasia.openevent.general.utils.Utils.setToolbar | ||
import org.fossasia.openevent.general.utils.extensions.nonNull | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
class SearchTypeFragment : Fragment() { | ||
private val searchTypeViewModel by viewModel<SearchTypeViewModel>() | ||
private val safeArgs: SearchTypeFragmentArgs by navArgs() | ||
private lateinit var rootView: View | ||
private val eventTypesList: MutableList<String> = ArrayList() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
rootView = inflater.inflate(R.layout.fragment_search_type, container, false) | ||
setToolbar(activity, "", hasUpEnabled = true) | ||
setHasOptionsMenu(true) | ||
searchTypeViewModel.loadEventTypes() | ||
val adapter = ArrayAdapter(context, R.layout.event_type_list, eventTypesList) | ||
rootView.eventTypesLv.adapter = adapter | ||
|
||
searchTypeViewModel.eventLocations | ||
.nonNull() | ||
.observe(this, Observer { list -> | ||
list.forEach { | ||
eventTypesList.add(it.name ?: "") | ||
} | ||
adapter.notifyDataSetChanged() | ||
}) | ||
rootView.eventTypesLv.setOnItemClickListener { parent, view, position, id -> | ||
redirectToSearch(eventTypesList[position]) | ||
} | ||
return rootView | ||
} | ||
|
||
private fun redirectToSearch(type: String) { | ||
val args = SearchFragmentArgs.Builder().setStringSavedType(type).build().toBundle() | ||
val navOptions = NavOptions.Builder().setPopUpTo(R.id.eventsFragment, false).build() | ||
Navigation.findNavController(rootView).navigate(R.id.searchFragment, args, navOptions) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/org/fossasia/openevent/general/search/SearchTypeViewModel.kt
This file contains hidden or 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,37 @@ | ||
package org.fossasia.openevent.general.search | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import io.reactivex.disposables.CompositeDisposable | ||
import io.reactivex.schedulers.Schedulers | ||
import org.fossasia.openevent.general.event.EventService | ||
import org.fossasia.openevent.general.event.types.EventType | ||
import timber.log.Timber | ||
|
||
class SearchTypeViewModel( | ||
private val eventService: EventService | ||
) : ViewModel() { | ||
|
||
private val compositeDisposable = CompositeDisposable() | ||
private val mutableEventLocations = MutableLiveData<List<EventType>>() | ||
val eventLocations: LiveData<List<EventType>> = mutableEventLocations | ||
|
||
fun loadEventTypes() { | ||
compositeDisposable.add(eventService.getEventTypes() | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe({ | ||
mutableEventLocations.value = it | ||
}, { | ||
Timber.e(it, "Error fetching events types") | ||
}) | ||
) | ||
} | ||
|
||
override fun onCleared() { | ||
super.onCleared() | ||
compositeDisposable.clear() | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<CheckedTextView | ||
android:id="@+id/text1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingStart="@dimen/layout_margin_large" | ||
android:paddingTop="@dimen/layout_margin_large" | ||
android:paddingBottom="@dimen/layout_margin_large" | ||
android:gravity="center_vertical" | ||
android:text="@string/anytime" | ||
android:background="?attr/selectableItemBackground" | ||
android:textColor="@color/black" | ||
android:textSize="@dimen/text_size_expanded_title" | ||
android:paddingLeft="@dimen/layout_margin_large" | ||
xmlns:android="http://schemas.android.com/apk/res/android" /> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.